Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cv2 show image
#1
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:

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)
Reply
#2
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.
Reply
#3
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.
Reply
#4
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'
Reply
#5
i think he forgot to add the
+ filename 
which coming from

filename = "opencv_frame_{}.png".format(img_counter)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PIL Image im.show() no show! Pedroski55 2 952 Sep-12-2022, 10:19 PM
Last Post: Pedroski55
  PIL Image im.show() no show! Pedroski55 6 4,864 Feb-08-2022, 06:32 AM
Last Post: Pedroski55
  show grayscale image using matplotlib zyb1003 1 16,505 Nov-01-2017, 11:45 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020