c++ - How can I count the number of tips in an image in OpenCV? -


i have set of hiragana characters , count number of end points/ tips character have.

example: input image:

enter image description here

desired output image:

enter image description here

i have tried using convex hull

enter image description here

code: (based on opencv tutorial here)

    findcontours(threshold_output, contours, hierarchy, cv_retr_tree, cv_chain_approx_simple, point(0, 0));      vector<vector<point> >hull(contours.size());      (int = 0; < contours.size(); i++)     {         convexhull(mat(contours[i]), hull[i], false);     }      mat drawing = mat::zeros(threshold_output.size(), cv_8uc3);     (int = 0; i< contours.size(); i++)     {         if (hierarchy[i][3] == 0) {             scalar color = scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));             drawcontours(drawing, hull, i, color, 1, 8, vector<vec4i>(), 0, point());         }     } 

then conrnerharris() returned many undesired corners

enter image description here

code: (based on opencv tutorial here)

    int blocksize = 2;     int aperturesize = 3;      /// detecting corners     drawing = binarizeimage(drawing); // otsu's     cornerharris(drawing, dst, blocksize, aperturesize, 0.04, border_default);      /// normalizing     normalize(dst, dst_norm, 0, 255, norm_minmax, cv_32fc1, mat());     convertscaleabs(dst_norm, dst_norm_scaled);      int countcorner = 0;      /// drawing circle around corners     (int j = 0; j < dst_norm.rows; j++)     {         (int = 0; < dst_norm.cols; i++)         {             if ((int)dst_norm.at<float>(j, i) > 50)             {                 circle(output, point(i, j), 2, scalar::all(255), -1, 8, 0);                 countcorner++;             }         }     } 

it detected 11 corners.

i'm thinking might same finger tip detection, don't know how it.

[i'm using opencv 2.4.9.]

i don't tend use opencv can need imagemagick, free , installed on linux distros , available osx , windows. so, had try imagemagick , maybe can adapt methods - done @ command line.

# thin input image down skeleton convert char.jpg -threshold 50% -negate -morphology thinning:-1 skeleton skeleton.jpg 

enter image description here

# find line-ends, using hit-or-miss morphology, , make them green (lime). save "lineends.jpg" convert skeleton.jpg -morphology hmt lineends -threshold 50% -fill lime -opaque white lineends.jpg 

enter image description here

# find line-junctions, using hit-or-miss morphology, , make them red. save "line junctions.jpg" convert skeleton.jpg -morphology hmt linejunctions -threshold 50% -fill red -opaque white linejunctions.jpg 

enter image description here

# superpose line-ends , line junctions result convert lineends.jpg linejunctions.jpg -compose lighten -composite result.jpg 

enter image description here

now have red , 2 green dots near line ends, , red dots near junctions, no matching green ones. so, count red dots have green dots nearby.

i'll show skeleton dots superimposed, can see how relate:

composite -blend 30% skeleton.jpg result.jpg z.jpg 

enter image description here


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -