Skip to main content

Prerequisites

Before starting, ensure you have OpenCV installed. See the Installation Guide if you haven’t already set up OpenCV.

Your First OpenCV Program

Let’s create a simple program to load and display an image.
1

Create your project

Create a new directory for your project:
2

Write your first program

Create a file and load an image:
Create display_image.py:
Make sure you have an image file named image.jpg in the same directory, or use cv.samples.findFile("starry_night.jpg") to use a built-in sample image.
3

Run your program

Execute your program:
A window will appear displaying your image. Press any key to close it, or press ‘s’ to save the image.

Basic Image Processing

Now let’s do some actual image processing:

Working with Video

Process video from a file or webcam:

Common Operations

Here are some frequently used OpenCV operations:

Reading and Writing

Image Transformations

Drawing

Next Steps

Now that you’ve created your first OpenCV program, explore more features:

Image Processing

Learn about filtering, transformations, and color spaces

Object Detection

Detect objects, faces, and features in images

Video Analysis

Process video streams and track objects

API Reference

Explore the complete OpenCV API

Troubleshooting

Make sure OpenCV is installed:
Verify installation:
This means the image couldn’t be loaded. Check:
  • The file path is correct
  • The image file exists
  • You have read permissions
  • The image format is supported
For headless environments, use a different backend:
Or save images instead of displaying them.
Try different camera indices:
On Linux, ensure you have camera permissions.

Resources