Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Reliable Video Capture in OpenCV from USB Video Capture Devices

I’m having some issues with USB video capture devices and OpenCV and am looking for a solution.

I am using OpenCV v3.4.2 in a Python 3.7 script on two different Windows 10 platforms.

  • Laptop that has a 2.8GHz Intel Core i7 processor and Intel HD 520 graphics adapter
  • Desktop computer with 3.5GHz Intel Core i7 and Nvidia GeForce TX 660 graphics adapter

The video signal is an NTSC standard definition stream coming from a security camera. I have three different capture cards:

  • Hauppauge USB Live-2
  • A generic HD capture device with HDMI in. This device is attached to an SD-to-HDMI up converter (signal > converter > HD capture)
  • A generic cheap standard definition capture device

My Python script instructs OpenCV to use the DirectShow API, but I believe OpenCV would default to DirectShow anyway when on Windows 10. Here are the results I’m getting for each of the three capture devices:

  • The Hauppauge gives similar results on both computers. It often takes 3 or 4 restarts of the script before I get a good display. The first few attempts are often a black image in the video window.
  • The HD capture device connects quickly with a good video on the laptop (it is horizontally stretched to fill out a 16:9 aspect ratio, but that is fine for my application). However, the video flickers a lot (unacceptable amount) on the desktop computer.
  • The generic cheap SD capture device doesn’t work on either computer. I’m not sure it has a DirectShow API.

Here is a sample script.

import cv2
cap = cv2.VideoCapture()
# The device number might be 0 or 1 depending on the device and the webcam
cap.open(0, cv2.CAP_DSHOW)
while(True):
    ret, frame = cap.read()
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

I want to use OpenCV in a Python script to reliably display a live video stream. Questions:

  1. Is there a way to reliably get a good video display the first time when using the Hauppauge USB Live-2 capture device?
  2. Why does the HDMI capture device and upconverter work on one computer but not the other when using the same Python script?
  3. Is there a known solution for how to get a good video display on both computers when using the HD capture device with the upconverter?
  4. Is there a recommendation for a reliable capture device? Standard definition NTSC is my first priority and HD (720p and/or 1080p) is second priority. I’m not concerned about 4K.

Reliable Video Capture in OpenCV from USB Video Capture Devices

I’m having some issues with USB video capture devices and OpenCV and am looking for a solution.

I am using OpenCV v3.4.2 in a Python 3.7 script on two different Windows 10 platforms.

  • Laptop that has a 2.8GHz Intel Core i7 processor and Intel HD 520 graphics adapter
  • Desktop computer with 3.5GHz Intel Core i7 and Nvidia GeForce TX 660 graphics adapter

The video signal is an NTSC standard definition stream coming from a security camera. I have three different capture cards:

  • Hauppauge USB Live-2
  • A generic HD capture device with HDMI in. This device is attached to an SD-to-HDMI up converter (signal > converter > HD capture)
  • A generic cheap standard definition capture device

My Python script instructs OpenCV to use the DirectShow API, but I believe OpenCV would default to DirectShow anyway when on Windows 10. Here are the results I’m getting for each of the three capture devices:

  • The Hauppauge gives similar results on both computers. It often takes 3 or 4 restarts of the script before I get a good display. The first few attempts are often a black image in the video window.
  • The HD capture device connects quickly with a good video on the laptop (it is horizontally stretched to fill out a 16:9 aspect ratio, but that is fine for my application). However, the video flickers a lot (unacceptable amount) on the desktop computer.
  • The generic cheap SD capture device doesn’t work on either computer. I’m not sure it has a DirectShow API.

Here is a sample script.

import cv2
cap = cv2.VideoCapture()
# The device number might be 0 or 1 depending on the device and the webcam
cap.open(0, cv2.CAP_DSHOW)
while(True):
    ret, frame = cap.read()
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

Note: The Python script works fine when the video source is the laptop's internal webcam.

I want to use OpenCV in a Python script to reliably display a live video stream. Questions:

  1. Is there a way to reliably get a good video display the first time when using the Hauppauge USB Live-2 capture device?
  2. Why does the HDMI capture device and upconverter work on one computer but not the other when using the same Python script?
  3. Is there a known solution for how to get a good video display on both computers when using the HD capture device with the upconverter?
  4. Is there a recommendation for a reliable capture device? Standard definition NTSC is my first priority and HD (720p and/or 1080p) is second priority. I’m not concerned about 4K.