cv2 show image - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: cv2 show image (/thread-22221.html) |
cv2 show image - mcgrim - Nov-04-2019 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: 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) RE: cv2 show image - baquerik - Nov-04-2019 Hallo Mcgrim, When you run this code path=r'C:\\Users\\PycharmProjects\\client-server' image = cv2.imread(path, 0)You are not specifying what image it should show, you only gave the path to the folder. RE: cv2 show image - mcgrim - Nov-04-2019 the code lines before line 23 are taking pics with the webcam and storing them in the folder I mention in line 24, so those images should show. RE: cv2 show image - baquerik - Nov-04-2019 I do not see how. csv2.imshow requires a path to an image, not a folder. Try changing the path to: path=r'C:\\Users\\PycharmProjects\\client-server\\name_of_the_picture.png' RE: cv2 show image - MckJohan - Nov-04-2019 i think he forgot to add the + filenamewhich coming from filename = "opencv_frame_{}.png".format(img_counter) |