A
A
Andrey Smirnov2020-01-28 00:20:55
Python
Andrey Smirnov, 2020-01-28 00:20:55

Why does WARN crash when working with a camera in OpenCV, Python?

There is a code that scans a QR code:

import cv2
import numpy as np
import pyzbar.pyzbar as pyzbar

cap = cv2.VideoCapture(0)

while True:
    _, frame = cap.read()

    decodedObjects = pyzbar.decode(frame)
    for obj in decodedObjects:
        print("Data", obj.data)

    cv2.imshow("Frame", frame)

    key = cv2.waitKey(1)
    if key == 27:
        break


Everything is working. It is necessary to make a function from this code that will return the first value received. When you try to change the line to to, the following is printed: [ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (674) SourceReaderCB ::~SourceReaderCB terminating async callback continues to work (does not crash), but no other code after the line of calling the resulting function is executed. What to do to fix this // suggest an alternative to make a function out of this. PS Directory C:\Projects\opencv-python\opencv\... not found on drive C:\ print("Data", obj.data)return obj.data






Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Dugin, 2020-01-28
@adugin

1) So you use return outside of the function? And what are you waiting for, except for an error?
2) Check the success of the returned result, and only then process the frame:

ret, frame = cap.read()
if ret:
    ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question