title: Error: !_img.empty() in function 'imwrite'
body: <p>I want to create frames from the video named <code>project.avi</code> and save them to <code>frameIn</code> folder. But some type of errors are not let me done. How can I solve this problem. Here is the code:</p>
  <pre><code>cap = cv2.VideoCapture('project.avi')
  
  currentFrame = 0
  
  while(True):
  
  ret, frame = cap.read()
  
  name = 'frameIn/frame' + str(currentFrame) + '.jpg'
  print (&quot;Creating file... &quot; + name)
  cv2.imwrite(name, frame)
  
  frames.append(name)
  
  currentFrame += 1
  
  cap.release()
  cv2.destroyAllWindows()
  </code></pre>
  <p>The error is:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;videoreader.py&quot;, line 28, in &lt;module&gt;
      cv2.imwrite(name, frame)
  cv2.error: OpenCV(4.4.0) /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-2rx9f0ng/opencv/modules/imgcodecs/src/loadsave.cpp:738: error: (-215:Assertion failed) !_img.empty() in function 'imwrite'
  </code></pre>