Java 使用 OpenCV (Canny) 进行边缘检测
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24174868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Edge detection using OpenCV (Canny)
提问by Arthur Emídio
I'm trying to detect rectangles using OpenCV. However, sometimes this is getting pretty difficult after running the Canny method, because two of the edges are usually being erased out. I've tried many different sets of thresholds and blurring it before applying Canny, but I haven't got major positive results yet. Currently, I'm not blurring the image, so this is pretty much what I'm doing:
我正在尝试使用 OpenCV 检测矩形。但是,有时在运行 Canny 方法后这会变得非常困难,因为通常会擦除两个边缘。在应用 Canny 之前,我尝试了许多不同的阈值集并对其进行了模糊处理,但我还没有得到重大的积极结果。目前,我没有模糊图像,所以这几乎就是我正在做的:
Mat imgSource = Highgui.imread(filepath);
Imgproc.Canny(imgSource, imgSource, 300, 600, 5, true);
Example:
例子:
original http://imagizer.imageshack.us/a/img822/8776/27i9j.jpgCanny http://imagizer.imageshack.us/a/img841/9868/wkc95.jpg
原创 http://imagizer.imageshack.us/a/img822/8776/27i9j.jpg Canny http://imagizer.imageshack.us/a/img841/9868/wkc95.jpg
Then, I'm trying OpenCV's findContours method to detect the rectangle, it works 80% of the time, how can I improve it?
然后,我正在尝试 OpenCV 的 findContours 方法来检测矩形,它在 80% 的时间内都有效,我该如何改进呢?
回答by Haris
Try with different threshold value, in this case you will get better result when using lower threshold values, like 10,100.
尝试使用不同的阈值,在这种情况下,使用较低的阈值(例如 10,100)会获得更好的结果。
blur(src,src,Size(3,3));
cvtColor(src,tmp,CV_BGR2GRAY);
Canny( src, thr, 10, 100, 3 );
Or in another way you will get the contour images by applying thresholdlike,
或者以另一种方式,您将通过应用阈值来获得轮廓图像 ,
threshold(tmp,thr,50,255,THRESH_BINARY_INV);
回答by Murad Dasi
the problem here is the image compression JPEG file type probably.
try converting image to monochromesince you only have Black/whiteimage
and edit the threshold value.
this should eliminate the noise around the edges of the lines.
then canny can be applied with any values.
这里的问题可能是图像压缩 JPEG 文件类型。
尝试将图像转换为单色,因为您只有黑白图像并编辑阈值。
这应该消除线条边缘周围的噪音。那么 canny 可以应用于任何值。