python opencv error

Asked 2 years ago, Updated 2 years ago, 60 views

import cv2

capture = cv2.VideoCapture(0) capture.set(cv2.CAP_PROP_FRAME_WIDTH, 640) capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

while True: ret, frame = capture.read() cv2.imshow("VideoFrame", frame) if cv2.waitKey(10) > 0: break

capture.release() cv2.destroyAllWindows()

I'm working on a code to film a video using a laptop cam repeatedly C:\Users\dntjd\PycharmProjects\practice\venv\Scripts\python.exe C:/Users/dntjd/PycharmProjects/practice/practice1.py Traceback (most recent call last): File "C:/Users/dntjd/PycharmProjects/practice/practice1.py", line 9, in cv2.imshow("VideoFrame", 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'

Process finished with exit code 1

I see this errorㅜ I'm posting a question because there's no clear solution no matter how much I look for it.

opencv

2022-09-21 20:52

2 Answers

Just looking at the error log, I think it's because the width and height of the image size are less than or equal to zero.

https://stackoverflow.com/questions/27953069/opencv-error-215size-width0-size-height0-in-function-imshow

https://stackoverflow.com/questions/43572387/error-215-size-width0-size-height0-occurred-when-attempting-to-display-a?noredirect=1&lq=1

You may not have been able to capture the image properly.


2022-09-21 20:52

Frame variable appears to contain a null value I don't think the camera is connected properly.


2022-09-21 20:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.