# VideoCapture open and source switching problems

I'm using Python 2.7.2 OpenCV on Win7 64 bit (but 32 bit Python) to display two cameras at once. I have only 2 capturable devices installed currently, a TV tuner on #0 and a webcam on #1.. I have a combobox that allows me to switch cameras for each display. Because of errors I had early on when both cameras would show the same video when trying to change video source, I prevent the two cameras from choosing the same index (the index given to VideoCapture.open(...)). However, because of weird behavior in 2.4.2 and in 2.4.3rc., I get these issues again.

Implementation:

I initialize each:

camera1 = cv2.VideoCapture(0)
camera2 = cv2.VideoCapture(1)


If the source is changed (to a valid index)

#camera.release() # test if this makes a difference
camera.open(index)
# checking camera.isOpen() always yields true, even for an index > 1


_,frame = camera.read()


Here are results of when errors occur. NOTE: I'm switch the camera inputs while BOTH CAMERAS ARE NOT GRABBING FRAMES.

Results in OpenCV 2.4.2:

• using camera.open(index) alone:

switching from #0 to anything > #1, I get camera #1.

switching from #1 to anything > #1, I get the following error when I call camera.read():

SystemError: NULL object passed to Py_BuildValue


This kills the thread handling that camera. The other camera will continue to operate fine unless I switch from some position that gives camera #1 to another position that gives camera #1, and I get the same error.

It seems that selecting a camera after the last "real" one gives the last real camera.

same behavior, but no errors. Also notice "setVideoSetting - QueryInterface Error" appears in console output when closing the program??

Results in OpenCV 2.4.3rc:

• using camera.open(index) alone:

no errors thrown, but it seems that the camera source can't change, always shows the starting source feed, can't change it.