Repository: opencv
Issue: Canny can not detect connected contour of black square on a white background.
Labels: bug,auto-transferred,priority: normal,affected: 3.4,category: ocl

Transferred from http://code.opencv.org/issues/4093

```
|| Vit Shiryaev on 2014-12-31 14:26
|| Priority: Normal
|| Affected: branch 'master' (3.0-dev)
|| Category: ocl
|| Tracker: Bug
|| Difficulty: 
|| PR: 
|| Platform: x86 / Windows
```
## Canny can not detect connected contour of black square on a white background.

```
Result of Simple code for simple image is not connected contour as it is expected, top or bottom edge missed depending on aperture parameter. Result printscreen is !http://answers.opencv.org/upfiles/14199661605456809.png! (see source image attached).

Code is:
<pre>
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?..
imshow("img", img);
imshow("canny3", imgGrayEdges3);
imshow("canny5", imgGrayEdges5);
waitKey();
</pre>

_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. According to some reports ( http://answers.opencv.org/question/52114/?answer=52128#post-id-52128 ) there are no such behaviour in 2.4_
```
## History
##### Nisarg Thakkar on 2015-01-08 06:31

```
Works for me. I get all the four sides. I'm using the latest version available on github.
```
##### Vit Shiryaev on 2015-01-08 11:23

```
Nisarg Thakkar, updated just now from github master, error remains the same. What is your cmake config (see my attached)?


-   File cmake-gui-out.txt added
```
##### Claudio Caraffi on 2015-01-08 16:15

```
Any possibility that it is a visualization aliasing problem? What about if you dump the image and open it with another visualization tool?
```
##### Vit Shiryaev on 2015-01-08 17:07

```
Claudio Caraffi, OpenCV function imshow(...) always use 100% scale thus no reason to do aliasing. I checked it before by "cout << imgGray.getMat(ACCESS_READ) << "\n" << imgGrayEdges3.getMat(ACCESS_READ)" as you can see from link to answers.opencv.org in report above. But I checked it with imwrite(..) and another visualization tool -- result is predictably the same.
```
##### Vit Shiryaev on 2015-01-12 21:18

```
I have tested this code for 2.4 on the same PC (using oclMat, see http://answers.opencv.org/question/52114/ comments), Canny works fine, no visible bugs.
```
##### Claudio Caraffi on 2015-01-13 12:38

```
I could reproduce the same bug on my machine. Equivalent OpenCL code works fine with OpenCV 2.4, has some inconsistencies in OpenCV 3.0. I tried with different "real" images, and compared the cv::Mat and cv::UMat versions, depending on the kernel size I have:
kernel 3: about 0.5% of edges missing (like 1500 pixels out of 300K).
kernel 5: about 0.1% of edges missing
kernel 7: something new appears, and something is missing, for a total of about 0.1% pixel different

I would change the title of this bug to "OpenCL Canny inconsistent with standard Canny"

OpenCV 3 built with MinGW4.9.2 32bit, IPP disabled, TBB enabled.
Note: Canny in version 3.0 is 4 times faster of version 2.9 (both OpenCL)!
```
##### Claudio Caraffi on 2015-01-14 14:09

```
I have created related issue http://code.opencv.org/issues/4120
```
##### Maksim Shabunin on 2015-04-27 09:12

```
-   Target version changed from 3.0-beta to 3.0
```
##### Maksim Shabunin on 2015-04-27 10:58

```
-   Category set to ocl
```