Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Canny边缘算法只需要一条边缘_C++_Opencv_Image Processing_Edge Detection_Mathematical Morphology - Fatal编程技术网

C++ Canny边缘算法只需要一条边缘

C++ Canny边缘算法只需要一条边缘,c++,opencv,image-processing,edge-detection,mathematical-morphology,C++,Opencv,Image Processing,Edge Detection,Mathematical Morphology,当我使用canny edge算法时,它会像预期的那样生成与粗彩色线相对的两条边,但我只想显示一条边,这样我的直线和曲线检测算法就不那么复杂了,有什么想法吗 代码如下: bool CannyEdgeDetection(DataStructure& col) { Mat src, src_gray; Mat dst, detected_edges, fin; int WhiteCount = 0, BCount = 0; char szFil1[32] = "ocv.bmp"; ch

当我使用canny edge算法时,它会像预期的那样生成与粗彩色线相对的两条边,但我只想显示一条边,这样我的直线和曲线检测算法就不那么复杂了,有什么想法吗

代码如下:

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;

}

这一过程称为
骨骼化
细化
。你可以用谷歌搜索

以下是骨骼化的
简单方法

下面是我将上述方法应用于图像时得到的
输出
图像在骨骼化之前是反转的,因为上述方法适用于黑色背景下的
白色图像
,与输入图像正好相反)


到目前为止,您尝试了什么?你能发一些代码吗?或者至少是输入图像?你能上传一个链接到你的原始图像吗?也许其他人可以提供更好的方法。最简单的方法是调整图像大小,使其足够小,使边缘为1-2像素。您将拥有1像素的canny边缘和即时性能提升。这看起来非常有用,为什么在图像处理中骨架化不比canny更受欢迎(我假设这是因为我根本没有听说过)。我不确定,但canny边缘检测是常用的,而且骨架化仍然是一种发展中的方法,每天都在准备更多的方法(我的回答中的方法不是很好)。无论如何,我还没有使用骨骼化技术。真是令人印象深刻!但是如果你不知道图像或背景的颜色,它会起作用吗?我不确定。在细化之前可能会检查黑白像素的数量,并决定是否反转,可能会起作用,因为通常背景的面积比前景大。我也能让它起作用。。但我不想把它颠倒过来。我应该评论哪一个(不是、和或)?
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);