Error (-215) size.width>0 && size.height>0 occurred when attempting to display an image using OpenCV

后端 未结 11 2574
渐次进展
渐次进展 2020-11-28 15:37

I am trying to run a simple program that reads an image from OpenCV. However, I am getting this error:

error: ......\\modules\\highgui\\src\\window.cpp:281:          


        
11条回答
  •  攒了一身酷
    2020-11-28 16:03

    import numpy as np
    import cv2
    
    cap = cv2.VideoCapture(0)
    while(True):
        # Capture frame-by-frame
        ret,frame = cap.read()
        cv2.rectangle(frame, (100, 100), (200, 200), [255, 0, 0], 2)
        # Display the resulting frame
        cv2.imshow('frame',frame)
        if cv2.waitKey(25) & 0xFF == ord('q'):
            break
    
    # When everything done, release the capture
    cap.release()
    cv2.destroyAllWindows() 
    

    **If the camera access for devices is OFF, this code gives an error ;kind of this: cv2.imshow('frame',frame) cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:350: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

    So You should turn ON it**
    

提交回复
热议问题