<ul dir="auto">
<li>OpenCV =&gt; 4.1 (opencv-python-headless 4.1.1.26)</li>
<li>Operating System / Platform =&gt; AWS ec2 instance running Ubuntu 18.04 AMI</li>
<li>Compiler =&gt; Whatever opencv-python uses to build the wheel</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">We encountered this bug at my place of work when extracting frames from a large number of videos. A cv2.VideoCapture instance from the opencv-python library would report success on reading frames that were beyond the end of the video file in question.</p>
<p dir="auto">I understand that this bug might be impossible to reproduce and I can't provide as much detail as I'd like to. There is also a fairly easy workaround I've put in place in case we don't find out the root cause, so don't hesitate to close this issue if you can't work with it.</p>
<p dir="auto">Nevertheless, I thought I would share this here on the off-chance that it's helpful or this is a known issue that has been fixed in a more recent version of OpenCV or may be fixed in a future release.</p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">Unfortunately, I've only seen this happen on ec2 instances at my place of work, with video files I'm not a liberty to share.</p>
<p dir="auto">However, below are the steps I took to confirm that the OpenCV python bindings or OpenCV itself was the cause of the bug. I ran an ipython shell on one of our virtual machines which was experiencing this issue:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [1]: import cv2                                                                                                   

In [2]: vc = cv2.VideoCapture('/tmp/tmpdoromkcr')                                                                    

In [3]: frame_count = vc.get(cv2.CAP_PROP_FRAME_COUNT)                                                               

In [4]: frame_count                                                                                                  
Out[4]: 62991.0

In [5]: vc.set(cv2.CAP_PROP_POS_FRAMES,  frame_count - 3600)                                                         
Out[5]: True

In [6]: success, frame = vc.read()                                                                                   

In [7]: success                                                                                                      
Out[7]: True

In [8]: frame                                                                                                        
Out[8]: 
array([[[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       ...,

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]]], dtype=uint8)

In [9]: frame.mean()                                                                                                 
Out[9]: 0.0018798225308641976

In [10]: vc.set(cv2.CAP_PROP_POS_FRAMES,  frame_count + 9999999999)                                                  
Out[10]: True

In [11]: success, frame = vc.read()                                                                                  

In [12]: success                                                                                                     
Out[12]: True

In [13]: frame                                                                                                       
Out[13]: 
array([[[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       ...,

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]]], dtype=uint8)

In [14]: frame.mean()                                                                                                
Out[14]: 0.0"><pre class="notranslate"><code class="notranslate">In [1]: import cv2                                                                                                   

In [2]: vc = cv2.VideoCapture('/tmp/tmpdoromkcr')                                                                    

In [3]: frame_count = vc.get(cv2.CAP_PROP_FRAME_COUNT)                                                               

In [4]: frame_count                                                                                                  
Out[4]: 62991.0

In [5]: vc.set(cv2.CAP_PROP_POS_FRAMES,  frame_count - 3600)                                                         
Out[5]: True

In [6]: success, frame = vc.read()                                                                                   

In [7]: success                                                                                                      
Out[7]: True

In [8]: frame                                                                                                        
Out[8]: 
array([[[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       ...,

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]]], dtype=uint8)

In [9]: frame.mean()                                                                                                 
Out[9]: 0.0018798225308641976

In [10]: vc.set(cv2.CAP_PROP_POS_FRAMES,  frame_count + 9999999999)                                                  
Out[10]: True

In [11]: success, frame = vc.read()                                                                                  

In [12]: success                                                                                                     
Out[12]: True

In [13]: frame                                                                                                       
Out[13]: 
array([[[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       ...,

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]]], dtype=uint8)

In [14]: frame.mean()                                                                                                
Out[14]: 0.0
</code></pre></div>
<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; :4.2.0:</li>
<li>Operating System / Platform =&gt; :Windows 7 4 Bit:</li>
<li>Compiler =&gt;:Not available:</li>
<li>Openvino =&gt; :2020.1:</li>
<li>Running on CPU</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">Importing model face-detection-adas-0001 Throws an error saying</p>
<blockquote>
<p dir="auto">Traceback (most recent call last):<br>
File "feed_network.py", line 50, in <br>
load_to_IE('C:\Users\ra\Desktop\projects\Entertainment\age-gender-face<br>
-detection-project\models\face-detection-adas-0001\FP16\face-detection-adas-<br>
0001.xml')<br>
File "feed_network.py", line 45, in load_to_IE<br>
plugin.load_network(net, device_name='CPU')<br>
File "ie_api.pyx", line 134, in openvino.inference_engine.ie_api.IECore.load_n<br>
etwork<br>
File "ie_api.pyx", line 141, in openvino.inference_engine.ie_api.IECore.load_n<br>
etwork<br>
<strong>RuntimeError: Failed to create plugin C:\Program Files (x86)\IntelSWTools\openvi<br>
no\deployment_tools\inference_engine\bin\intel64\Release\MKLDNNPlugin.dll for de<br>
vice CPU</strong><br>
Please, check your environment<br>
Cannot load library 'C:\Program Files (x86)\IntelSWTools\openvino\deployment_too<br>
ls\inference_engine\bin\intel64\Release\MKLDNNPlugin.dll': 3221225501 from cwd:<br>
C:\Users\ra\Desktop\projects\Entertainment\age-gender-face-detection-project\han<br>
dling_inference</p>
</blockquote>

<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">My code is</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#def load_to_IE(model_xml):
    ##load the inference engine api
    plugin = IECore()
    #Load  IR files into their related class
    model_bin = os.path.splitext(model_xml)[0] + '.bin'
    net = IENetwork(model=model_xml, weights=model_bin)
    #load the network in the inference engine
    plugin.load_network(net, device_name='CPU')
    print(&quot;IR loaded successfully&quot;)
    
    return

load_to_IE('C:\\Users\\ra\\Desktop\\projects\\Entertainment\\age-gender-face-detection-project\\models\\face-detection-adas-0001\\FP16\\face-detection-adas-0001.xml')"><pre class="notranslate"><code class="notranslate">#def load_to_IE(model_xml):
    ##load the inference engine api
    plugin = IECore()
    #Load  IR files into their related class
    model_bin = os.path.splitext(model_xml)[0] + '.bin'
    net = IENetwork(model=model_xml, weights=model_bin)
    #load the network in the inference engine
    plugin.load_network(net, device_name='CPU')
    print("IR loaded successfully")
    
    return

load_to_IE('C:\\Users\\ra\\Desktop\\projects\\Entertainment\\age-gender-face-detection-project\\models\\face-detection-adas-0001\\FP16\\face-detection-adas-0001.xml')
</code></pre></div>