The simple answer is: you are doing it wrong. See the documentation - what you do is calculate the derivative d^2/(dx dy) image - this means "how the horizontal edges change vertically" (or, equivalently, "how the vertical edges change horizontally"), that is, for vertical or horizontal edge you expect the exit of zero (because it does not change in the direction perpendicular to it). So what you do 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 collect these results and add them, then take the square root from the result. This can lead to what GIMP does.
source share