Nov-04-2019, 01:35 PM
I am trying to display the images I take with the webcam.
The iteration presents no issue, but right after the loop is finished,
I get this error:
Here is my code
The iteration presents no issue, but right after the loop is finished,
I get this error:
Error:[ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (674) SourceReaderCB::~SourceReaderCB terminating async callback
Traceback (most recent call last):
File "C:/Users/PycharmProjects/client-server/cv_attempt.py", line 29, in <module>
cv2.imshow('image', image)
cv2.error: OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:352: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
how do I display these images?Here is my code
import cv2 import time capture = cv2.VideoCapture(0) capture.set(3, 640) capture.set(4, 480) img_counter = 0 start_time = time.time() while (img_counter< 5): ret, frame = capture.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.imshow('frame', gray) if cv2.waitKey(1) & 0xFF == ord('q'): break if time.time() - start_time >= 1: # how often (secs) are pics taken filename = "opencv_frame_{}.png".format(img_counter) cv2.imwrite(filename, frame) start_time = time.time() img_counter += 1 print("{} written!".format(img_counter)) capture.release() path=r'C:\\Users\\PycharmProjects\\client-server' image = cv2.imread(path, 0) cv2.imshow('image', image)