2
import cv2
import numpy as np

cap = cv2.VideoCapture(0)

while True:
    ret,frame = cap.read()
    cv2.imshow('frame',frame)
    k = cv2.waitKEy(10) & 0xff
    if k == 27:
        break

cap.release()
cv2.destroyAllWindows()

Hi all I'm a beginner and I'm just trying to video capture using opencv but I'm just confused because I get:

error(-215) size.width>0 && size.height>0 in function imshow

and I cant find whats exactly wrong with it. Any help is greatly appreciated.

My exact error is

Traceback (most recent call last):
File "/home/pi/Desktop/videocapture.py", line 8,in <module>
  cv2.imshow('frame',frame)
Error: /home/pi/opencv-3.0.0/modules/highgui/src/window.cpp:271: error: (-215) size.width>0 && size.height>0 in function imshow

And I tried a few other ways as well but and sometimes I will get scn == 3||scn == 4

Biruk Abebe
  • 2,174
  • 1
  • 10
  • 23
  • After `ret,frame = cap.read()` you need to check `ret` to make sure that capture succeeded. Ideally also make sure that `frame` is not empty, before you start using it. Trying to show an empty image (one where width or height are 0) is an error. – Dan Mašek May 22 '16 at 14:26

1 Answers1

-1

i got the same problem when i first processed image,and i guess if the problem of python3 and then same problem came when turn to python2.7.Last,trying to use absolute image path replace relative path,fortunately, it works.

ikinest
  • 11
  • 3