OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow

前端 未结 1 973
心在旅途
心在旅途 2021-01-16 16:55

I am running the following code on Raspberry Pi with pi camera, I have the broadcom drivers for it and all, but I am getting an error. Perhaps something to do with the dimen

相关标签:
1条回答
  • 2021-01-16 17:15

    Provide an id to VideoCapture.

    cap = cv2.VideoCapture(0)
    

    Also check the value of ret, see if it's TRUE or FALSE

    print (ret)
    

    Edit:

    To capture a video, you need to create a VideoCapture object. Its argument can be either the device index or the name of a video file. Device index is just the number to specify which camera.

    cap = cv2.VideoCapture(0)

    To check whether the cap has been initialized or not, you can use cap.isOpened() function, which returns True for successful initialization and False for failure.

    if cap.isOpened() == False:
        print ("VideoCapture failed")
    

    cap.read() returns a bool (True/False). If frame is read correctly, it will be True. So you can check end of the video by checking this return value.

    ret, frame = cap.read()
    if ret == False:
        print("Frame is empty")
    

    Further reading here.

    0 讨论(0)
提交回复
热议问题