html5 - How can I find a colored marker inside of an image using HTML 5 Canvas and Javascript? -
i have user-uploaded form trying crop based on location of colored markers inside image.
using fabric.js , tracking.js, can identify these markers under ideal conditions (i.e. when user scans image on flatbed scanner).
now, want make system more robust allowing user capture image smartphone, meaning image on average darker , colored markers harder find.!
i can programmatically adjust brightness of image without problems, unable reliably detect locations of markers.
i develop algorithm find area of image highest concentration of blue, , record coordinates around it.
here example of form:

any appreciated!
here's 1 method use:
use context.getimagedata pixel data of image.
convert each pixel it's hsl equivalent. hsl values allow more identify colors "bluish" rather absolutely blue. mention, identifying colors not absolute requirement of source image might contain "noise" or contains imperfect brightness , contrast levels.
the "h" in hsl think of color. might declare original blue hue plus/minus 5% of original hue might identified "bluish".
calculate average x , average y position of "bluish" pixels. average point towards blue target.
you don't mention needing average x/y of black targets. if have more 1 target of same color (like black) must adjust calculation sorting black pixels general area on image.
one way of dealing multiple black targets to:
find blackish pixel. can iterating pixel array until find one.
create bounding box around pixel twice size of target heart.
calculate average blackish x/y inside bounding box identify blackish target average.
now tricky part...reset pixels in bounding box transparent. refetch pixel array of modified image , search. eliminate "already found" first blackish target when searching next blackish target.
good luck project!
Comments
Post a Comment