c++ - Extracting Junction point in skeleton -


i working opencv , c++ in project @ school . problem how extract junction point in skeleton image . have tried develop code doesn't work , didn't find mistake . in advance .

int main( int argc, char** argv ) { cv::mat im = cv::imread("img.jpg",0); if (im.empty())     return -1; cv::mat img_rgb(im.size(), cv_8uc3); cv::threshold(img_rgb, img_rgb, 155, 255, cv_thresh_binary); cv::cvtcolor(im, img_rgb, cv_gray2rgb);  int s=0;      (int = 1; < img_rgb.rows-1; i++)     {     (int j = 1; j < img_rgb.cols-1; j++)     {      if(255 == img_rgb.at<uchar>(i,j))     {         uchar p1 = img_rgb.at<uchar>(i, j);         uchar p2 = img_rgb.at<uchar>(i-1, j);         uchar p3 = img_rgb.at<uchar>(i-1, j+1);         uchar p4 = img_rgb.at<uchar>(i, j+1);         uchar p5 = img_rgb.at<uchar>(i+1, j+1);         uchar p6 = img_rgb.at<uchar>(i+1, j);         uchar p7 = img_rgb.at<uchar>(i+1, j-1);         uchar p8 = img_rgb.at<uchar>(i, j-1);         uchar p9 = img_rgb.at<uchar>(i-1, j-1);        // s = abs(p9-p8)+abs(p8-p7)+abs(p7-p6)+abs(p6-p5)+abs(p5-p4)+abs(p4-p3)+abs(p3-p2)+abs(p2-p9);         //    if (s == 1530)                  int same=(p9==p1);                  same+=(p8==p1);                 same+=(p7==p1);                  same+=(p6==p1);                  same+=(p5==p1);                  same+=(p4==p1);                  same+=(p3==p1);                  same+=(p2==p1);               if (same==2)               {           //                   cout<<i<<" "<<j<<" " <<same<<endl;     circle(img_rgb,point(i,j),1,scalar(0, 255, 0),1);             }      }     } }  cv::imshow("a",img_rgb); cv::waitkey();  return 0 ; 

}

you're thresholding img_rgb, empty @ moment.

also, why conversion gray rgb, again ? (btw, if loop on rgb image, mat.at<uchar>(y,x) wrong, should mat.at<vec3b>(y,x) )

i'd say, skip gray2rgb conversion, , instead threshold grayscale image loaded:

cv::mat im = cv::imread("img.jpg",0); if (im.empty())     return -1;  cv::mat thresh; cv::threshold(im, thresh, 155, 255, cv_thresh_binary); 

and use mat further processing:

for (int = 1; < thresh.rows-1; i++) {     (int j = 1; j < thresh.cols-1; j++)     {         uchar p1 = thresh.at<uchar>(i, j);         if(255 == p1)         {                 uchar p2 = thresh.at<uchar>(i-1, j);              uchar p3 = thresh.at<uchar>(i-1, j+1);               // ... 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -