So I am attempting to capture from two cameras in openCV (python & windows 7). I capture from one camera just fine, youll also notice I am doing some funky stuff to the image but that doesn't matter. This is the code to attempt to use two
import cv
import time
cv.NamedWindow("camera", 1)
cv.NamedWindow("camera2", 1)
capture = cv.CaptureFromCAM(0)
capture2 = cv.CaptureFromCAM(1)
while True:
img = cv.GetMat(cv.QueryFrame(capture))
img2 = cv.GetMat(cv.QueryFrame(capture2))
dst_image = cv.CloneMat(img)
dst_image2 = cv.CloneMat(img2)
cv.ConvertScale(img, dst_image, 255, -59745.0)
cv.ConvertScale(img2, dst_image2, 255, -59745.0)
cv.ShowImage("camera", dst_image)
cv.ShowImage("camera2", dst_image2)
if cv.WaitKey(10) == 27:
cv.DestroyWindow("camera")
cv.DestroyWindow("camera2")
break
Rather simple. However it won't work. Upon trying to create the matrix from the second camera (second line of code in the loop), I am told that the capture is null. The cameras I am using are logitech and are the same model.
Side note: I also couldnt find the command to count cameras connected in python, so if someone could refer me to that I'd much appreciate it. --Ashley
EDIT: It might also be useful to know that windows often prompts me to choose which camera I would like to use. I can't seem to avoid this behavior. Additionally I downloaded some security like software that successful runs both cameras at once. It is not open source or anything like that. So clearly, this is possible.