简体   繁体   中英

openCV vs GIMP, edge detection fails in openCV

I am doing Sobel edge detection in openCV using the with following parameters:

cv.Sobel(mat, edgemat, 1, 1)
# mat -> source image
# edgemat -> taget output image 
# 1 -> xorder (int) – Order of the derivative x
# 1 -> yorder (int) – Order of the derivative y
# apertureSize (int) – Size of the extended Sobel kernel -> its by default set to 3

I also did the Sobel edge detection on the image using GIMP.

The source image is:源图像 The output by openCV is openCV 输出The output by GIMP is GIMP 输出

Why such a big difference between the outputs by openCV and GIMP. The quality of output by GIMP surpasses openCV by light years.

Simple answer: You are doing it wrong. See the documentation - what you are doing is computing the d^2/(dx dy) derivative of the image - that means "how do the horizontal edges change vertically" (or, equivalently, "how do the vertical edges change horizontally"), that means, for a vertical or horizontal edge you expect an output of zero (because it doesn't change in the direction perpendicular to it). So, what you are doing with your opencv line is not edge detection at all. You probably want something like sobel with 1, 0 as parameters and 0, 1 , then square those results and add them up, then take the square root of the result. That might result in something like what GIMP is doing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM