Ask Your Question

Reliable Video Capture in OpenCV from USB Video Capture Devices

asked 2020-04-27 11:47:44 -0500

slalomchip gravatar image

updated 2020-04-27 15:39:25 -0500

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, cv2.CAP_DSHOW)
    ret, frame =
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):

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.
edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2020-06-30 02:56:08 -0500

guivi01 gravatar image

I am having the same problem with the Hauppauge USB Live-2. Had this problem for years. Although I program in C++ but likely you problem comes from the same place as mine.

A quick hack is to identify how long does it take for opencv to retrieve a frame and if it is too long ~1 second then restart the connection to the video device, not a pretty hack but it has helped me many times.

I have try to figure out where the problem is happening and It has to do with the videoInput library which opencv uses internally. I have Tested the videoInput by itself and I have managed to reproduce the same problem.

edit flag offensive delete link more

Question Tools



Asked: 2020-04-27 11:47:44 -0500

Seen: 2,574 times

Last updated: Apr 27 '20