Hi guys,
I try to use two USB cams at the same time, one uses VideoCapture()
with CAP_MSMF
(thermal camera) and the other one with CAP_DSHOW
(webcam).
System: Windows 10 (20H2)
Python: 3.9.4
opencv-python: 4.5.2.52
Both programs work fine if itself if started as single application, but if I start both at the same time, then the camera which uses CAP_MSMF
ends with the following error message during read()
:
[ WARN:0] global C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-m8us58q4\opencv\modules\videoio\src\cap_msmf.cpp (1021) CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -2147483638
This is how the call of the webcam with CAP_DSHOW
looks like:
# initialize the video stream
print("[INFO] starting video stream...")
vs = VideoStream(src=1) # call inside WebcamVideoStream class: self.stream = cv2.VideoCapture(src, cv2.CAP_DSHOW)
print("CAP_PROP_FRAME_WIDTH")
vs.stream.stream.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
print("CAP_PROP_FRAME_HEIGHT")
vs.stream.stream.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
print("CAP_PROP_FPS")
vs.stream.stream.set(cv2.CAP_PROP_FPS, 25)
vs.start()
# loop over the frames from the video stream
while True:
# grab the frame from the threaded video stream
frame = vs.read()
...
# not relevant frame processing snipped
cv2.imshow("webcam_tf", frame)
if cv2.waitKey(20) == 27:
break
This is how the call of the thermal cam with CAP_MSMF
looks like:
print("starting thermalcam...")
cv2.namedWindow("thermalcam")
cap = cv2.VideoCapture(0, cv2.CAP_MSMF)
print("CAP_PROP_FPS")
cap.set(cv2.CAP_PROP_FPS, 25)
# request raw data from CV
cap.set(cv2.CAP_PROP_CONVERT_RGB, 0)
# request raw data from camera
cap.set(cv2.CAP_PROP_ZOOM, 0x8004)
# shutter
cap.set(cv2.CAP_PROP_ZOOM, 32768)
if cap.isOpened(): # try to get the first frame
print("Read first frame")
rval, frame = cap.read()
else:
print("Error opening webcam")
rval = False
if rval:
print("Start cyclic reading")
while True:
# WEBCAM
rval, frame = cap.read()
if not rval:
break
...
# not relevant frame processing snipped
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
heatmap_gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
heatmap = cv2.applyColorMap(heatmap_gray, cv2.COLORMAP_HOT)
heatmap = imutils.resize(heatmap, width=640)
cv2.imshow("thermalcam", heatmap)
if cv2.waitKey(20) == 27:
break
I actually load both cameras into separate processes, means they should not use the same ressources inside Python for sure.
This error even happens if I start the second camera in a separate Python (Miniconda) environment.
Any idea what could cause this problem on the CAP_MSMF
device if a second device with CAP_DSHOW
gets started?