K
K
Kirushkaa2020-12-09 22:33:36
Python
Kirushkaa, 2020-12-09 22:33:36

Why doesn't cv2.Imshow() output an image?

Hi all! Faced the problem that the imshow function creates a window that is always unresponsive. Thus the script like as should work. macOS system. There is 100% access to the camera.

The code itself:

import cv2

cap = cv2.VideoCapture(0)

while True:
    ret, img = cap.read()
    cv2.imshow("camera", img)
    if cv2.waitKey(10) == 27:
        break
cap.release()
cv2.destroyAllWindows()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Dugin, 2020-12-09
@adugin

import cv2

cap = cv2.VideoCapture(0)

while True:
    ret, img = cap.read()
    if ret:  # <<<<< этот параметр вам не просто так выдают
        cv2.imshow("camera", img)
    if cv2.waitKey(10) & 0xFF == 27:  # <<<<< 0xFF
        break

cap.release()
cv2.destroyAllWindows()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question