Using OpenCV to read input from Capture Card

125 views Asked by At

I am trying to use OpenCV in Python to read the feed coming from my Elgato HD 60 pro capture card but I keep running into errors. If you don't think OpenCV is the right tool for this I would greatly appreciate alternative options. I verified that my Capture card works and then I tried to use an to date version of Python and OpenCV but I could not get it to recognize my device. Firstly, I tried something like the following to try and locate my capture card.

def find_capture_device_id(max_tests=10):
    for device_id in range(max_tests):
        capture = cv2.VideoCapture(device_id)
        if capture is None or not capture.isOpened():
            if capture is not None:
                capture.release()
            continue

        ret, frame = capture.read()
        capture.release()

        if ret:
            print(f"Device ID {device_id} is available and returns valid frames.")
        else:
            print(f"Device ID {device_id} is available but does not return valid frames.")

This yielded multiple errors although I am fairly sure that Camera index out of range errors just means I enumerated past the last device meaning I only have 1 connected on my pc which has the DeviceId of 0 and what I assume to be my capture card. However, even the first device (indexed with 0) still does not work correctly since it says it does not have any valid frames.

[ WARN:[email protected]] global cap_msmf.cpp:1768 CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -2147483638
Device ID 0 is available but does not return valid frames.
[ERROR:[email protected]] global obsensor_uvc_stream_channel.cpp:159 cv::obsensor::getStreamChannelGroup Camera index out of range
[ERROR:[email protected]] global obsensor_uvc_stream_channel.cpp:159 cv::obsensor::getStreamChannelGroup Camera index out of range
[ERROR:[email protected]] global obsensor_uvc_stream_channel.cpp:159 cv::obsensor::getStreamChannelGroup Camera index out of range
[ERROR:[email protected]] global obsensor_uvc_stream_channel.cpp:159 cv::obsensor::getStreamChannelGroup Camera index out of range
[ERROR:[email protected]] global obsensor_uvc_stream_channel.cpp:159 cv::obsensor::getStreamChannelGroup Camera index out of range
[ERROR:[email protected]] global obsensor_uvc_stream_channel.cpp:159 cv::obsensor::getStreamChannelGroup Camera index out of range
[ERROR:[email protected]] global obsensor_uvc_stream_channel.cpp:159 cv::obsensor::getStreamChannelGroup Camera index out of range
[ERROR:[email protected]] global obsensor_uvc_stream_channel.cpp:159 cv::obsensor::getStreamChannelGroup Camera index out of range
[ERROR:[email protected]] global obsensor_uvc_stream_channel.cpp:159 cv::obsensor::getStreamChannelGroup Camera index out of range

Next I went to device manager then went to "Sound, video and game controllers" and found the one labeled "Game Capture H60 pro". Next I went to its properties and then went to the Compatible Ids tab. This contained many results such as "PCI\VEN_12AB&DEV_0380&REV_00", "PCI\VEN_12AB&DEV_0380" and so on which I tried to use to ensure I am capturing the right device.

    vendor_id = "12AB"
    device_id = "0380"

    # Combine them into the device ID string
    device_id_string = f"PCI\\VEN_{vendor_id}&DEV_{device_id}"

    # Try different capture methods
    capture = cv2.VideoCapture(device_id_string)
    if not capture.isOpened():
        # Try using cv2.CAP_DSHOW
        capture = cv2.VideoCapture(cv2.CAP_DSHOW)
        if not capture.isOpened():
            # Try using cv2.CAP_VFW
            capture = cv2.VideoCapture(cv2.CAP_VFW)
            if not capture.isOpened():
                print(f"Device ID {device_id_string} is not available or does not return valid frames.")
                return

    print("Pass")

This sadly also failed and also resulted in the following errors.

Device ID PCI\VEN_12AB&DEV_0380 is not available or does not return valid frames.
[ WARN:[email protected]] global cap.cpp:344 cv::VideoCapture::open VIDEOIO(DSHOW): backend is generally available but can't be used to capture by index

So my question is what am I doing wrong? How can I configure OpenCV or any other AI tool to be able to read from my capture card?

0

There are 0 answers