i've ran in issue concerning generating floating point coordinates image.
the original problem follows: input image handwritten text. want generate set of points (just x,y coordinates) make individual characters.
at first used findcontours in order generate points. since finds edges of characters first needs ran through thinning algorithm, since i'm not interested in shape of characters, lines or in case, points.
input:
thinning:
so, run input through thinning algorithm , fine, output looks good. running findcontours on not work out good, skips lot of stuff , end unusable.
the second idea generate bounding boxes (with findcontours), use these bounding boxes grab characters thinning process , grab none-white pixel indices "points" , offset them bounding box position. generates worse output, , seems bad method.
horrible code this:
mat temp = new mat(edges, bb); byte roi_buff[] = new byte[(int) (temp.total() * temp.channels())]; temp.get(0, 0, roi_buff); int cols = temp.cols(); list<point> prearraylist = new arraylist<point>(); for(int = 0; < roi_buff.length; i++) { if(roi_buff[i] != 0) { point tempp = bb.tl(); tempp.x += i%cols; tempp.y += i/cols; prearraylist.add(tempp); } }
is there alternatives or overlooking something?
update:
i overlooked fact need points (pixels) ordered. in method above scanline approach grabbing pixels. if @ 'o' example, grab first point on left hand side, 1 on right hand side. need them ordered neighbouring pixels since want draw paths points later on (outside of opencv). possible?
you should implementing own connected components labelling. concept simple: scan first line , assign unique labels each horizontally connected strip of pixels. check every pixel if connected left neighbour , assign either neighbour's label or new label. in second row same, check against pixels above it. need label merge: 2 strips not connected in previous row joined in current row. way deal either keep list of label equivalences or use pointers labels (so can complete label change object).
this findcontours does, if implement have freedom go 8-connectedness , bridge single-pixel or two-pixel gap. way "almost-connected components labelling". looks need "w" in example picture.
once have image labelled way, can push pixels of single label vector, , order them this. find top left pixel, push new vector , erase original vector. find pixel in original vector closest it, push new vector , erase original. continue until pixels have been transferred.
it not fast way, should start.
Comments
Post a Comment