<p dir="auto">Transferred from <a href="http://code.opencv.org/issues/2461" rel="nofollow">http://code.opencv.org/issues/2461</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="|| Walter Blume on 2012-10-19 17:20
|| Priority: Normal
|| Affected: None
|| Category: imgproc, video
|| Tracker: Bug
|| Difficulty: None
|| PR: None
|| Platform: None / None"><pre class="notranslate"><code class="notranslate">|| Walter Blume on 2012-10-19 17:20
|| Priority: Normal
|| Affected: None
|| Category: imgproc, video
|| Tracker: Bug
|| Difficulty: None
|| PR: None
|| Platform: None / None
</code></pre></div>
<h2 dir="auto">hough circle detection not symmetric, misses obvious circle</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="For some reason the Hough circle detection misses an obvious circle, but if I flip the image, the circle is detected.  One would think that results would be similar with flipped image, but they are not.

Attached is source code and test input image that exhibited the problem.  Also screenshot with arrow showing the obvious circle miss.

Using OpenCV 2.4.2, built with TBB on Windows7 64 bit machine"><pre class="notranslate"><code class="notranslate">For some reason the Hough circle detection misses an obvious circle, but if I flip the image, the circle is detected.  One would think that results would be similar with flipped image, but they are not.

Attached is source code and test input image that exhibited the problem.  Also screenshot with arrow showing the obvious circle miss.

Using OpenCV 2.4.2, built with TBB on Windows7 64 bit machine
</code></pre></div>
<h2 dir="auto">History</h2>
<h5 dir="auto">Daniil Osokin on 2012-10-22 06:34</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Thank you, we will check it.
-   Category set to imgproc, video"><pre class="notranslate"><code class="notranslate">Thank you, we will check it.
-   Category set to imgproc, video
</code></pre></div>
<h5 dir="auto">Jason Harper on 2014-02-22 23:04</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="The problem is in the non-maxima suppression. It is only checking if a value that passes the threshold is also larger (but not equal) than all of it's neighbors.  In the first case there are two pixels with equal values next to each other.  When that happens neither pixel is set as a possible center and the circle is ignored.  When the image is flipped one of these pixels gets an extra count leaving a single peak which gets labeled as a possible center.  

I changed the check to &gt;= and it fixed the problem and will submit a pull request soon."><pre class="notranslate"><code class="notranslate">The problem is in the non-maxima suppression. It is only checking if a value that passes the threshold is also larger (but not equal) than all of it's neighbors.  In the first case there are two pixels with equal values next to each other.  When that happens neither pixel is set as a possible center and the circle is ignored.  When the image is flipped one of these pixels gets an extra count leaving a single peak which gets labeled as a possible center.  

I changed the check to &gt;= and it fixed the problem and will submit a pull request soon.
</code></pre></div>
<h5 dir="auto">leonardo bocchi on 2015-06-01 15:59</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="I faced the same problem, and found the same solution.
To avoid duplication, I changed lines 1112-1113 of hough.cpp to read:

           adata[base] &gt;= adata[base-1] &amp;&amp; adata[base] &gt; adata[base+1] &amp;&amp;
           adata[base] &gt;= adata[base-acols-2] &amp;&amp; adata[base] &gt; adata[base+acols+2] )

It seems working and no duplicate detections."><pre class="notranslate"><code class="notranslate">I faced the same problem, and found the same solution.
To avoid duplication, I changed lines 1112-1113 of hough.cpp to read:

           adata[base] &gt;= adata[base-1] &amp;&amp; adata[base] &gt; adata[base+1] &amp;&amp;
           adata[base] &gt;= adata[base-acols-2] &amp;&amp; adata[base] &gt; adata[base+acols+2] )

It seems working and no duplicate detections.
</code></pre></div>
<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt;  4.0.0</li>
<li>Operating System / Platform =&gt; Ubuntu 16.04</li>
<li>GPU =&gt; NVIDIA GeForce GTX 1080</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">As I read the changelog for opencv 4.0.0 the dnn module option <code class="notranslate">setPreferableTarget(DNN_TARGET_OPENCL)</code> was fixed.<br>
For this, I installed and test the version 4.0.0 and test that openCL backend is using my gpu. But, when I run my code with this option the code is still running on cpu. I looked htop with and without ````setPreferableTarget``` and both ways load the cpu equals. Also, measure time and it is the same for both ways. For this I searched about openCL and check that Opencv is really using my gpu. When I run</p>
<div class="highlight highlight-source-c++ notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="std::vector&lt; cv::ocl::PlatformInfo &gt; platform_info;
if (!cv::ocl::haveOpenCL())
{
	cout &lt;&lt; &quot;OpenCL is not available...&quot; &lt;&lt; endl;
	//return;
}
cv::ocl::setUseOpenCL(true);
ocl::getPlatfomsInfo(platform_info);

for(int i = 0; i &lt; platform_info.size(); i++){
	ocl::PlatformInfo sdk = platform_info.at(i);
	for (int j = 0; j &lt; sdk.deviceNumber(); j++) {
		ocl::Device device;
		sdk.getDevice(device, j);

		cout &lt;&lt; &quot;\n\n*********************\n Device &quot; &lt;&lt; i + 1 &lt;&lt; endl;
		cout &lt;&lt; &quot;Vendor ID: &quot; &lt;&lt; device.vendorID() &lt;&lt; endl;
		cout &lt;&lt; &quot;Vendor name: &quot; &lt;&lt; device.vendorName() &lt;&lt; endl;
		cout &lt;&lt; &quot;Name: &quot; &lt;&lt; device.name() &lt;&lt; endl;
		cout &lt;&lt; &quot;Driver version: &quot; &lt;&lt; device.driverVersion() &lt;&lt; endl;
		cout &lt;&lt; &quot;available: &quot; &lt;&lt; device.available() &lt;&lt; endl;

		if (device.isAMD()) cout &lt;&lt; &quot;Is an AMD device&quot; &lt;&lt; endl;
		if (device.isIntel()) cout &lt;&lt; &quot;Is a Intel device&quot; &lt;&lt; endl;

		cout &lt;&lt; &quot;Global Memory size: &quot; &lt;&lt; device.globalMemSize() &lt;&lt; endl;
		cout &lt;&lt; &quot;Memory cache size: &quot; &lt;&lt; device.globalMemCacheSize() &lt;&lt; endl;
		cout &lt;&lt; &quot;Memory cache type: &quot; &lt;&lt; device.globalMemCacheType() &lt;&lt; endl;
		cout &lt;&lt; &quot;Local Memory size: &quot; &lt;&lt; device.localMemSize() &lt;&lt; endl;
		cout &lt;&lt; &quot;Local Memory type: &quot; &lt;&lt; device.localMemType() &lt;&lt; endl;
		cout &lt;&lt; &quot;Max Clock frequency: &quot; &lt;&lt; device.maxClockFrequency() &lt;&lt; endl;

	}
}"><pre class="notranslate">std::vector&lt; cv::ocl::PlatformInfo &gt; platform_info;
<span class="pl-k">if</span> (!cv::ocl::haveOpenCL())
{
	cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>OpenCL is not available...<span class="pl-pds">"</span></span> &lt;&lt; endl;
	<span class="pl-c"><span class="pl-c">//</span>return;</span>
}
<span class="pl-en">cv::ocl::setUseOpenCL</span>(<span class="pl-c1">true</span>);
<span class="pl-en">ocl::getPlatfomsInfo</span>(platform_info);

<span class="pl-k">for</span>(<span class="pl-k">int</span> i = <span class="pl-c1">0</span>; i &lt; platform_info.size(); i++){
	ocl::PlatformInfo sdk = platform_info.<span class="pl-c1">at</span>(i);
	<span class="pl-k">for</span> (<span class="pl-k">int</span> j = <span class="pl-c1">0</span>; j &lt; sdk.<span class="pl-c1">deviceNumber</span>(); j++) {
		ocl::Device device;
		sdk.<span class="pl-c1">getDevice</span>(device, j);

		cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span><span class="pl-cce">\n\n</span>*********************<span class="pl-cce">\n</span> Device <span class="pl-pds">"</span></span> &lt;&lt; i + <span class="pl-c1">1</span> &lt;&lt; endl;
		cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>Vendor ID: <span class="pl-pds">"</span></span> &lt;&lt; device.<span class="pl-c1">vendorID</span>() &lt;&lt; endl;
		cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>Vendor name: <span class="pl-pds">"</span></span> &lt;&lt; device.<span class="pl-c1">vendorName</span>() &lt;&lt; endl;
		cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>Name: <span class="pl-pds">"</span></span> &lt;&lt; device.<span class="pl-c1">name</span>() &lt;&lt; endl;
		cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>Driver version: <span class="pl-pds">"</span></span> &lt;&lt; device.<span class="pl-c1">driverVersion</span>() &lt;&lt; endl;
		cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>available: <span class="pl-pds">"</span></span> &lt;&lt; device.<span class="pl-c1">available</span>() &lt;&lt; endl;

		<span class="pl-k">if</span> (device.<span class="pl-c1">isAMD</span>()) cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>Is an AMD device<span class="pl-pds">"</span></span> &lt;&lt; endl;
		<span class="pl-k">if</span> (device.<span class="pl-c1">isIntel</span>()) cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>Is a Intel device<span class="pl-pds">"</span></span> &lt;&lt; endl;

		cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>Global Memory size: <span class="pl-pds">"</span></span> &lt;&lt; device.<span class="pl-c1">globalMemSize</span>() &lt;&lt; endl;
		cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>Memory cache size: <span class="pl-pds">"</span></span> &lt;&lt; device.<span class="pl-c1">globalMemCacheSize</span>() &lt;&lt; endl;
		cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>Memory cache type: <span class="pl-pds">"</span></span> &lt;&lt; device.<span class="pl-c1">globalMemCacheType</span>() &lt;&lt; endl;
		cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>Local Memory size: <span class="pl-pds">"</span></span> &lt;&lt; device.<span class="pl-c1">localMemSize</span>() &lt;&lt; endl;
		cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>Local Memory type: <span class="pl-pds">"</span></span> &lt;&lt; device.<span class="pl-c1">localMemType</span>() &lt;&lt; endl;
		cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>Max Clock frequency: <span class="pl-pds">"</span></span> &lt;&lt; device.<span class="pl-c1">maxClockFrequency</span>() &lt;&lt; endl;

	}
}</pre></div>
<p dir="auto">output is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="*********************
 Device 1
Vendor ID: 2
Vendor name: Intel(R) Corporation
Name: Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
Driver version: 1.2.0.37
available: 1
Is a Intel device
Global Memory size: 16782102528
Memory cache size: 262144
Memory cache type: 2
Local Memory size: 32768
Local Memory type: 2
Max Clock frequency: 3400


*********************
 Device 2
Vendor ID: 3
Vendor name: NVIDIA Corporation
Name: GeForce GTX 1080
Driver version: 384.130
available: 1
Global Memory size: 8499691520
Memory cache size: 327680
Memory cache type: 2
Local Memory size: 49152
Local Memory type: 1
Max Clock frequency: 1733"><pre class="notranslate"><code class="notranslate">*********************
 Device 1
Vendor ID: 2
Vendor name: Intel(R) Corporation
Name: Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
Driver version: 1.2.0.37
available: 1
Is a Intel device
Global Memory size: 16782102528
Memory cache size: 262144
Memory cache type: 2
Local Memory size: 32768
Local Memory type: 2
Max Clock frequency: 3400


*********************
 Device 2
Vendor ID: 3
Vendor name: NVIDIA Corporation
Name: GeForce GTX 1080
Driver version: 384.130
available: 1
Global Memory size: 8499691520
Memory cache size: 327680
Memory cache type: 2
Local Memory size: 49152
Local Memory type: 1
Max Clock frequency: 1733
</code></pre></div>
<p dir="auto">OpenCL detect the gpu, this is good. But when run this,</p>
<div class="highlight highlight-source-c++ notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="cv::ocl::Context context;
if (!context.create(cv::ocl::Device::TYPE_ALL))
{
	cout &lt;&lt; &quot;Failed creating the context...&quot; &lt;&lt; endl;
	//return;
}
cout &lt;&lt; &quot;**********************&quot;&lt;&lt;endl;
cout &lt;&lt; context.ndevices() &lt;&lt; &quot; GPU devices are detected.&quot; &lt;&lt; endl; //This bit provides an overview of the OpenCL devices you have in your computer
for (int i = 0; i &lt; context.ndevices(); i++)
{
	cv::ocl::Device device = context.device(i);
	cout &lt;&lt; &quot;name:              &quot; &lt;&lt; device.name() &lt;&lt; endl;
	cout &lt;&lt; &quot;available:         &quot; &lt;&lt; device.available() &lt;&lt; endl;
	cout &lt;&lt; &quot;imageSupport:      &quot; &lt;&lt; device.imageSupport() &lt;&lt; endl;
	cout &lt;&lt; &quot;OpenCL_C_Version:  &quot; &lt;&lt; device.OpenCL_C_Version() &lt;&lt; endl;
	cout &lt;&lt; endl;
}
"><pre class="notranslate">cv::ocl::Context context;
<span class="pl-k">if</span> (!context.create(cv::ocl::Device::TYPE_ALL))
{
	cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>Failed creating the context...<span class="pl-pds">"</span></span> &lt;&lt; endl;
	<span class="pl-c"><span class="pl-c">//</span>return;</span>
}
cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>**********************<span class="pl-pds">"</span></span>&lt;&lt;endl;
cout &lt;&lt; context.ndevices() &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span> GPU devices are detected.<span class="pl-pds">"</span></span> &lt;&lt; endl; <span class="pl-c"><span class="pl-c">//</span>This bit provides an overview of the OpenCL devices you have in your computer</span>
<span class="pl-k">for</span> (<span class="pl-k">int</span> i = <span class="pl-c1">0</span>; i &lt; context.ndevices(); i++)
{
	cv::ocl::Device device = context.<span class="pl-c1">device</span>(i);
	cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>name:              <span class="pl-pds">"</span></span> &lt;&lt; device.<span class="pl-c1">name</span>() &lt;&lt; endl;
	cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>available:         <span class="pl-pds">"</span></span> &lt;&lt; device.<span class="pl-c1">available</span>() &lt;&lt; endl;
	cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>imageSupport:      <span class="pl-pds">"</span></span> &lt;&lt; device.<span class="pl-c1">imageSupport</span>() &lt;&lt; endl;
	cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>OpenCL_C_Version:  <span class="pl-pds">"</span></span> &lt;&lt; device.<span class="pl-c1">OpenCL_C_Version</span>() &lt;&lt; endl;
	cout &lt;&lt; endl;
}
</pre></div>
<p dir="auto">In the output only detect the intel gpu.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="**********************
1 GPU devices are detected.
name:              Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
available:         1
imageSupport:      1
OpenCL_C_Version:  OpenCL C 2.0 "><pre class="notranslate"><code class="notranslate">**********************
1 GPU devices are detected.
name:              Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
available:         1
imageSupport:      1
OpenCL_C_Version:  OpenCL C 2.0 
</code></pre></div>
<p dir="auto">I don't know how to <strong>set openCL for use Nvidia Gpu</strong>  and after that check if dnnTarget is using it in forward.</p>

<h5 dir="auto">Steps to reproduce</h5>