cv2.VideoCapture.read() prevent hidapi from receiving more data
I have a usb2 video camera and an hid usb device connected on the same board.
I can read data from the hid device using hidapi and it works fine.
However, as soon as I do:
success, frame = video_capture.read()
hid.read()
will never return anything anymore. Freezes there forever (if I use a timeout of 0).
Any idea why it would do this? Does the read()
function do anything to reserve the usb bus or anything?
EDIT1:
Some more info:
If I do video_capture.release()
then I can read from hid again. Until I do video_capture.read()
which re-freezes hid.
Also the video_capture.read()
will block hid reads even if 2 different python scripts.
- I start a first script that reads from hid in a loop first and it does it's thing reading and printing the result.
- Then I start a second script that reads from the webcam.
Once the webcam script is started, the hid script freeze at read(). The webcam script is fine.
EDIT2:
This will reproduce the issue. It will print 1 hid report and then 1 time True
and stop on the next hid read.
import cv2
import time
import hid
_hid = hid.device()
_hid.open(0x04D8, 0x00DD)
video_capture = cv2.VideoCapture(0)
video_capture.set(cv2.CAP_PROP_BUFFERSIZE, 1)
video_capture.set(cv2.CAP_PROP_FRAME_WIDTH, 320)
video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 240)
while True:
report = b"\x10"
_hid.write(b"\0" + report + b"\0" * (64 - len(report)))
print(_hid.read(64))
success, frame = video_capture.read()
print(success)
time.sleep(1)
I'm running
- Language => Python 3.8.3
- OpenCV => 4.3.0
- Operating System / Platform => Debian GNU/Linux 10 on armv7l
have you tried with other usb devices (i.e a mouse) ?
can you be more specific ?
Snippet:
No I tried only the mcp2221a, I'll give a mouse a try.