top of page

How to Communicate with USB UVC Camera Using OpenCV on Ubuntu

How to Communicate with USB UVC Camera Using OpenCV

In many embedded vision and industrial imaging applications such as surveillance systems, robotics, AI-based inspection, and machine vision, capturing and processing video from a USB camera is a fundamental requirement.

Modern USB cameras that support UVC (USB Video Class) can be easily integrated into Linux systems without installing additional drivers. This makes them ideal for developers working on rapid prototyping, computer vision research, and production-grade vision systems.

In this guide, we provide a step-by-step walkthrough for communicating with a USB UVC camera using OpenCV on Ubuntu. The process is simple, developer-friendly, and works with both color and monochrome USB cameras.

By the end of this tutorial, you will be able to:
  • Detect a USB camera on Ubuntu

  • Install and configure OpenCV

  • Capture live video streams using Python

  • Build a basic camera streaming application


Platform Details Used in This Setup

The following environment was used for testing this setup:

Operating System: Ubuntu 22.04.5 LTS

Kernel Version: 6.8.0-100-generic

Camera Interface: USB 3.2 Gen 1 Camera

Software Library: OpenCV (Python)

This procedure is compatible with most USB UVC compliant cameras, including industrial and embedded vision cameras.


1. What is UVC?

UVC (USB Video Class) is a standard protocol that allows USB cameras to communicate with a host system without requiring custom drivers.

If your camera:

  • Works immediately after connecting

  • Does not require a special driver installation

  • Appears as /dev/video0 in Linux

Then it is most likely a UVC compliant camera.

Ubuntu already has built-in UVC driver support using V4L2 (Video4Linux2).

Ubuntu provides native support for UVC devices through Video4Linux2 (V4L2), which allows applications such as OpenCV, GStreamer, and VLC to directly access the camera stream.

This makes USB cameras extremely convenient for rapid development and prototyping of vision applications.


2. Installing OpenCV on Ubuntu

Before accessing the camera stream, we need to install OpenCV, a widely used computer vision library.

Update System Packages

sudo apt update

Install Python Package Manager (If pip is not already installed)

sudo apt install python3-pip

Install OpenCV

pip3 install opencv-python

Verify Installation (Run the following command)

python3 -c "import cv2; print (cv2. __version__)"
If the version number prints successfully, OpenCV has been installed correctly.

3. Check Camera Detection in Ubuntu

After connecting the USB camera, confirm that Ubuntu detects it correctly.

List Available Video Devices

ls /dev/video*

You may see something similar to:

/dev/video0
/dev/video1

Usually:

  • /dev/video0 → First connected camera

  • /dev/video1 → Second camera

Check Detailed Device Information

v4l2-ctl --list-devices

If the v4l2-ctl tool is not installed, install it using:

sudo apt install v4l-utils

This command displays detailed information about connected cameras and confirms whether the device is recognized by the system.


4. Basic OpenCV Streaming Code

Now let's create a simple Python script to stream video from the USB camera.

Create a Python File

nano stream_uvc.py

Paste the Following Code

import cv2
 
# Open camera (0 = first camera)
cap = cv2.VideoCapture(0)
 
# Set resolution (optional)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
 
if not cap.isOpened():
    print("Error: Cannot open camera")
    exit()
 
while True:
    ret, frame = cap.read()
 
    if not ret:
        print("Failed to grab frame")
        break
 
    cv2.imshow("USB UVC Camera Stream", frame)
 
    # Press 'q' to exit
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
 
cap.release()
cv2.destroyAllWindows()

Save the file and exit the editor.

This script:

  • Opens the USB camera

  • Sets the streaming resolution

  • Captures frames continuously

  • Displays the live video feed in a window


5. Run the Code

Now execute the script:

python3 stream_uvc.py

A camera preview window will open showing the live video stream from the USB camera.

To close the stream, simply press:

q

Why USB UVC Cameras Are Ideal for Vision Development

USB UVC cameras provide a plug-and-play imaging solution for developers working on computer vision and embedded vision applications.

Key advantages include:

  • No driver installation required

  • Native Linux support via V4L2

  • Easy integration with OpenCV and Python

  • Faster prototyping for AI and machine vision systems

  • Compatibility with robotics, inspection, and surveillance applications

Industrial USB cameras such as the Falcon 821CRS USB Camera combine high-performance imaging sensors with full UVC compatibility, enabling developers to quickly build and deploy scalable vision systems.

If you're developing AI vision, robotics, smart surveillance, or industrial inspection solutions, choosing the right camera platform is critical.

Check out our Falcon Series – USB 3.2 Gen 1 Cameras portfolio to find the camera that best suits your application.

contact form camera BG image (1).webp
contact form camera image.webp
Reach Vadzo Team for the Customization

Vadzo team shall be able to assist you with the details on this.

Talk to our Camera Expert

bottom of page