Canny (OCL, 3-beta) can not detect connected contour of black square on a white background.
Simple code for simple image result is not connected contour as it is expected. Top or bottom edge missed. Result printscreen is square-bug.png . The picture itself is square.png. Code is:
void test(){
UMat img = imread("./square.png", IMREAD_COLOR).getUMat(ACCESS_READ);
UMat imgGray, imgGrayEdges3, imgGrayEdges5;
cvtColor(img, imgGray, CV_BGR2GRAY);
Canny(imgGray, imgGrayEdges3, 50, 150, 3);
Canny(imgGray, imgGrayEdges5, 300, 2000, 5); // why so large thresholds?..
cout << imgGray.getMat(ACCESS_READ) << "\n" << imgGrayEdges3.getMat(ACCESS_READ) << "\n" << imgGrayEdges5.getMat(ACCESS_READ) ;
imshow("img", img);
imshow("canny3", imgGrayEdges3);
imshow("canny5", imgGrayEdges5);
waitKey();
}
Am I doing something wrong?
I use OpenCV3-beta in Eclipse under Win8.1 and have to build source from git. Source updated and compiled today (last canny.cpp change was 7 weeks ago). I do have openCL so I guess UMat Canny function uses OCL_RUN version of function
UPDATE: device and system info
- Driver Packaging
- Version 14.501.1003-141120a-178000C
- Catalyst Version 14.12 AMD Catalyst
- Omega Software 2D Driver
- Version 8.01.01.1443 Direct3D
- Version 9.14.10.01080 OpenGL
- Version 6.14.10.13283 Mantle Driver
Version 9.1.
- Graphics Chipset AMD Radeon HD 7900 Series
- BIOS Version 015.012.000.004
- BIOS Part Number 113-C3860100-100
- BIOS Date 2011/12/07
Well.. no ideas. Bug reported: http://code.opencv.org/issues/4093
Can you share on which hardware and driver this happen? Did you test with OpenCV 2.4? The code would be only slightly different, example:
Which works correctly for me by the way
BTW: The answer to: "Why so large threshold" is that when using 5 as kernel size of Canny, at an intermediate stage you get a Sobel image computed with the mask 5 parameters, which has much larger multipliers, and of course convolves a larger number of pixels.
@Antonio, thanks for your answer. I tested Canny and it is ok in 2.4 with this test picture, your code works perfect. The problem is actual for OpenCV3-beta only. Post updated by soft- and hardware info.
As for threshold, from my point of view it is more convenient to have normalized output i.e. threshold should not be a function of another parameters, this increases the code hidden-errors possibility.
@Vit I confirm 100% your findings: OpenCV3 OpenCL implementation of Canny it's buggy. (Although is 4 times faster)
BTW, did you build 32bit or 64bit? In my case, 32bit
@Antonio, thanks for you informative report on OpenCV bug-tracker. I hope this will activate works on that issue. According to attached "cmake-gui-out.txt" file there I have 32-bit version.