<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; 3.4.2,  3.4.5 and 4.1.0</li>
<li>Operating System / Platform =&gt; Windows and Linux x64</li>
<li>Compiler =&gt; gcc and python bindings</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">There is a large difference in calculations after the first batch normalization layer when I use a convolutional model with the opencv dnn module. The model is made with Keras/Tensorflow 1.14. The graph is frozen and then saved in binary .pb format.</p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">Here is the model up to the batch norm layer in text format<br>
<a href="https://www.dropbox.com/s/tujdf3uvd7heyn1/test_batchnorm.pbtxt?dl=0" rel="nofollow">https://www.dropbox.com/s/tujdf3uvd7heyn1/test_batchnorm.pbtxt?dl=0</a><br>
Here is the model up to the batch norm layer in binary format<br>
<a href="https://www.dropbox.com/s/eyndn1xh42x3qr3/test_batchnorm.pb?dl=0" rel="nofollow">https://www.dropbox.com/s/eyndn1xh42x3qr3/test_batchnorm.pb?dl=0</a></p>
<p dir="auto">Here is a test image ( grayscale, should be rescaled in range 0..1, before passing as input)<br>
<a href="https://www.dropbox.com/s/gtghtp06k8jk5vy/00001.png?dl=0" rel="nofollow">https://www.dropbox.com/s/gtghtp06k8jk5vy/00001.png?dl=0</a><br>
And the outputs generated with the python binding<br>
Here is the output of the batch norm in Tensorflow<br>
<a href="https://www.dropbox.com/sh/xwkdjwbsoarxqna/AADrZ9BmWK5UUGRBN9t1I6moa?dl=0" rel="nofollow">https://www.dropbox.com/sh/xwkdjwbsoarxqna/AADrZ9BmWK5UUGRBN9t1I6moa?dl=0</a><br>
Here is the output of the batch norm in OpenCV<br>
<a href="https://www.dropbox.com/sh/520m2w74045tlqc/AAAUl3CAzE0r498go7BsMxRea?dl=0" rel="nofollow">https://www.dropbox.com/sh/520m2w74045tlqc/AAAUl3CAzE0r498go7BsMxRea?dl=0</a></p>
<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; 3.2.0</li>
<li>Operating System / Platform =&gt; Ubuntu 18.04</li>
<li>Compiler =&gt; c++</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">When I create a binary image with few pixels and call <code class="notranslate">findContours</code>, it seems to me that some points are skipped. Code example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#include &lt;opencv2/opencv.hpp&gt;

int main()
{
  uchar img_data[] = {255, 255, 255, 0, 0, 0, 255, 0, 255, 0, 255, 0, 255, 0, 0};
  cv::Mat img(cv::Size(5, 3), CV_8UC1, img_data);

  cv::imshow(&quot;img&quot;, img);
  cv::waitKey();

  std::vector&lt;std::vector&lt;cv::Point&gt;&gt; contours;
  std::vector&lt;cv::Vec4i&gt; hierarchy;
  cv::findContours(img, contours, hierarchy, cv::RETR_TREE,
      cv::CHAIN_APPROX_NONE);

  for (std::vector&lt;cv::Point&gt; contour : contours)
  {
    for (cv::Point p : contour)
    {
      std::cout &lt;&lt; p &lt;&lt; std::endl;
    }
  }
}"><pre class="notranslate"><code class="notranslate">#include &lt;opencv2/opencv.hpp&gt;

int main()
{
  uchar img_data[] = {255, 255, 255, 0, 0, 0, 255, 0, 255, 0, 255, 0, 255, 0, 0};
  cv::Mat img(cv::Size(5, 3), CV_8UC1, img_data);

  cv::imshow("img", img);
  cv::waitKey();

  std::vector&lt;std::vector&lt;cv::Point&gt;&gt; contours;
  std::vector&lt;cv::Vec4i&gt; hierarchy;
  cv::findContours(img, contours, hierarchy, cv::RETR_TREE,
      cv::CHAIN_APPROX_NONE);

  for (std::vector&lt;cv::Point&gt; contour : contours)
  {
    for (cv::Point p : contour)
    {
      std::cout &lt;&lt; p &lt;&lt; std::endl;
    }
  }
}
</code></pre></div>
<p dir="auto">I expect the points [0,0], [0,1], [1,1], [1,2], [0,2], [0,3], [1,2], [1,2], [2,2], [2,3], [3,3], [3,2], [4,2], [4,1] and [3,0] to show up. Instead the output is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[0, 0]
[1, 1]
[0, 2]
[1, 1]
[2, 2]
[3, 1]
[2, 0]
[1, 0]
[1, 1]
[2, 0]
[3, 1]
[2, 2]"><pre class="notranslate"><code class="notranslate">[0, 0]
[1, 1]
[0, 2]
[1, 1]
[2, 2]
[3, 1]
[2, 0]
[1, 0]
[1, 1]
[2, 0]
[3, 1]
[2, 2]
</code></pre></div>
<p dir="auto">The problem gets clearer if the image is scaled by a positive value. Then, most of the structures are recognizable, but in the corners there are diagonals instead of harsh 90 degree angles. The diagonal neighboring pixels seems to be replaced with a diagonal line. So it seems to me that 8-connectivity is used as default. For my case, I'd like to use 4-connectivity. Is there any way to do this? Thanks-</p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">Use above code.</p>