Only one edge needed in the Canny edge algorithm

When I use the canny edge algorithm, it creates 2 edges opposite the thick color line, as expected, but I want only one edge to be displayed to make the line and curve detection algorithm much less complicated, any ideas about how I can do this?

enter image description here

Here is the code:

bool CannyEdgeDetection(DataStructure& col) { Mat src, src_gray; Mat dst, detected_edges, fin; int WhiteCount = 0, BCount = 0; char szFil1[32] = "ocv.bmp"; char szFil2[32] = "dst.bmp"; src = imread(szFil1); dst = imread(szFil1); blur( src_gray, detected_edges, Size(3,3) ); Canny( src, dst, 100, 200, 3 ); imwrite(szFil2, dst ); IplImage* img = cvLoadImage(szFil2); int height = img->height; int width = img->width; int step = img->widthStep; int channels = img->nChannels; uchar * datau = (uchar *)img->imageData; for(int i=0;i<height;i++){ for(int j=0;j<width;j++){ for(int k=0;k<channels;k++){ datau[i*step+j*channels+k] = 255 - datau[i*step+j*channels+k]; if (datau[i*step+j*channels+k]==0){ WhiteCount++; col.pixel_col [i][j] = 2; } else{BCount++; col.pixel_col[i][j] = 0; } } } } cvSaveImage("img.bmp" ,img); return 0; } 

This is not an original image, but similar:

enter image description here

What part do I comment to read black images on a white background? or any color image?

 bool done; do { cv::morphologyEx(img, temp, cv::MORPH_OPEN, element); cv::bitwise_not(temp, temp); cv::bitwise_and(img, temp, temp); cv::bitwise_or(skel, temp, skel); cv::erode(img, img, element); double max; cv::minMaxLoc(img, 0, &max); done = (max == 0); } while (!done); 
+7
source share
1 answer

This process is called skeletonization or thinning . You can use this for Google.

Here is a simple method for skeletonization : OpenCV simple method for skeletonization in C #

Below is the output I received when applying the above method to your image ( The image is inverted before skeletonization , because the above method works for white images in black background , just opposite your input image).

enter image description here

+2
source

All Articles