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

<ul dir="auto">
<li>OpenCV =&gt; Latest 4.0.0 (Master Branch)</li>
<li>Operating System / Platform =&gt; Ubuntu 18.04.1 LTS</li>
<li>Compiler =&gt; GCC 7.3.0</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">All Python Bindings Seems Broken:(See below)</p>
<p dir="auto">Python 2.7.15rc1:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="abhishek@abhishek-HP-Pavilion-Notebook:~/Downloads/opencv-master/build_tbb$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
[GCC 7.3.0] on linux2
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt; import cv2
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
ImportError: /usr/local/lib/python2.7/dist-packages/cv2.so: undefined symbol: _ZN2cv8Stitcher17estimateTransformERKNS_11_InputArrayE
&gt;&gt;&gt; "><pre class="notranslate"><code class="notranslate">abhishek@abhishek-HP-Pavilion-Notebook:~/Downloads/opencv-master/build_tbb$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import cv2
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
ImportError: /usr/local/lib/python2.7/dist-packages/cv2.so: undefined symbol: _ZN2cv8Stitcher17estimateTransformERKNS_11_InputArrayE
&gt;&gt;&gt; 
</code></pre></div>
<p dir="auto">Python 3.6.6:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="abhishek@abhishek-HP-Pavilion-Notebook:~/Downloads/opencv-master/build_tbb$ python3
Python 3.6.6 (default, Sep 12 2018, 18:26:19) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt; import cv2
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
ImportError: /usr/local/lib/python3.6/dist-packages/cv2.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZN2cv8Stitcher17estimateTransformERKNS_11_InputArrayE
&gt;&gt;&gt; "><pre class="notranslate"><code class="notranslate">abhishek@abhishek-HP-Pavilion-Notebook:~/Downloads/opencv-master/build_tbb$ python3
Python 3.6.6 (default, Sep 12 2018, 18:26:19) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import cv2
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
ImportError: /usr/local/lib/python3.6/dist-packages/cv2.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZN2cv8Stitcher17estimateTransformERKNS_11_InputArrayE
&gt;&gt;&gt; 
</code></pre></div>
<h5 dir="auto">Debug Files:</h5>
<p dir="auto">Strace:<br>
<a href="https://github.com/opencv/opencv/files/2601226/python2.txt">python2.txt</a><br>
<a href="https://github.com/opencv/opencv/files/2601227/python3.txt">python3.txt</a></p>
<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; 3.4+</li>
<li>Operating System / Platform =&gt; windows</li>
<li>Compiler =&gt; MSVC debug with _DEBUG macro defined</li>
</ul>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">The following c++ code fails in assert inside Mat::elemSize</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="int f()
{
    cv::Mat1b m(2, 2);
    auto crop = m(cv::Rect(0,0,0,0));
    int res = cv::sum(crop)[0]; // assert fails in Mat::elemSize
    return res;
}"><pre class="notranslate"><code class="notranslate">int f()
{
    cv::Mat1b m(2, 2);
    auto crop = m(cv::Rect(0,0,0,0));
    int res = cv::sum(crop)[0]; // assert fails in Mat::elemSize
    return res;
}
</code></pre></div>
<h5 dir="auto">Detailed description:</h5>
<p dir="auto">Matrix ctor calls Mat::release() in case of rows==0 &amp;&amp; cols==0.<br>
In debug mode (if _DEBUG is defined) Mat::release() sets dims to 0.<br>
Thus Mat::dims variable has different values in debug and release after the construction of the matrix.</p>
<h5 dir="auto">expected behavior:</h5>
<p dir="auto">assert fails only in case of an uninitialized matrix.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="cv::sum(cv::Mat()); // should fail
cv::Mat1b m(2, 2);
cv::sum(m(cv::Rect(0,0,0,0))); // should not fail"><pre class="notranslate"><code class="notranslate">cv::sum(cv::Mat()); // should fail
cv::Mat1b m(2, 2);
cv::sum(m(cv::Rect(0,0,0,0))); // should not fail
</code></pre></div>
<p dir="auto">Mat is expected to have the same dims value in release and debug</p>
<p dir="auto">possible fix:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="--- a/modules/core/src/matrix.cpp
+++ b/modules/core/src/matrix.cpp
@@ -475,6 +475,7 @@ Mat::Mat(const Mat&amp; m, const Rect&amp; roi)
     if( rows &lt;= 0 || cols &lt;= 0 )
     {
         release();
+        dims = 2;
         rows = cols = 0;
     }
 }"><pre class="notranslate"><code class="notranslate">--- a/modules/core/src/matrix.cpp
+++ b/modules/core/src/matrix.cpp
@@ -475,6 +475,7 @@ Mat::Mat(const Mat&amp; m, const Rect&amp; roi)
     if( rows &lt;= 0 || cols &lt;= 0 )
     {
         release();
+        dims = 2;
         rows = cols = 0;
     }
 }
</code></pre></div>