Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 54 ยท Getting Started

What Is OpenCV?

OpenCV is the open-source library for computer vision: images, video, edges, features and detection. See what it does, how it is built and how this course runs.

A photo is just a grid of numbers. Computer vision is the craft of turning those numbers into answers: where is the edge of the page, how many coins are on the table, is the red ball moving left? OpenCV (Open Source Computer Vision Library) is the toolbox most people reach for first. It has been developed for over two decades, it is free under a permissive license, and it runs on desktops, servers, phones and small boards.

In this lesson you will see what OpenCV contains, how it is put together, and how this course teaches it on a website that cannot run the real library. You do not need any prior computer-vision knowledge, but you should be comfortable with basic Python.

What OpenCV does

OpenCV bundles hundreds of ready-made algorithms. A few families cover most day-to-day work:

What OpenCV gives you

Image basics Read, write, resize, crop and recolor.
Processing Blur, sharpen, threshold and clean up.
Shapes Edges, contours, lines and circles.
Video Cameras, frames and motion.

These four cover most beginner projects.

1 / 2

Each family has its own chapter in this course. Chapter by chapter you move from "what is a pixel" to a working document scanner.

How a computer sees an image

To a person, a photo is a scene. To a computer, it is a grid of numbers. Each small square, a pixel, stores one number for brightness (a grayscale image) or three numbers for color (blue, green and red in OpenCV). So an image is a matrix: a 640 by 480 color photo is a table of 480 rows and 640 columns where every cell holds three values from 0 to 255. Every vision algorithm is, in the end, arithmetic on this matrix. That idea is why the same library can blur a picture, measure an object, or feed a neural network: they all start with the numbers. The next lessons show this in code, starting with Images Are NumPy Arrays.

A typical program has three stages: input (read a file or grab a frame from a camera), processing (filter, transform, detect, match) and output (draw results, save a file, show a window, or send a number to another system such as a robot).

Where OpenCV is used

OpenCV runs behind many everyday and industrial systems:

  • Robotics and autonomous systems: lane following, obstacle detection, visual odometry and mapping.
  • Medical imaging: enhancing X-rays, counting cells, segmenting organs in scans.
  • Security and access: face detection, license plate reading, motion alerts.
  • Manufacturing: inspecting parts for defects, measuring sizes, reading barcodes and QR codes.
  • Photography and apps: panoramas, HDR, document scanning, filters and augmented reality.
  • Agriculture, satellites and astronomy: crop health, land-cover maps, aligning and stacking exposures.
  • Gesture and body tracking: controlling devices with hands, fitness apps, sports analysis.

Strengths and limits

Advantages: it is free and open source (Apache 2 license), fast because the core is optimized C++ with SIMD and optional GPU backends, available from Python, C++, Java and JavaScript, runs on Windows, Linux, macOS, Android and iOS, and has a huge community and thousands of tutorials.

Limitations: the classic algorithms need careful tuning for each lighting condition and camera, so they are brittle compared with modern deep learning; the built-in GUI is basic; the Python function names are terse and error messages from C++ can be hard to read; and some algorithms (SIFT used to be one) have been covered by patents. For hard recognition problems you will usually combine OpenCV for pre- and post-processing with a neural network, as in The dnn Module.

How OpenCV is built

OpenCV is written in C++ for speed, and many routines are tuned further with SIMD instructions, multiple threads and optional GPU backends. You rarely call that C++ directly. Instead you use a binding: a thin layer that exposes the same functions to another language. The Python binding is by far the most popular and lives in a module called cv2 (the name is historical; it does not mean version 2).

graph LR
    P["Your Python code"] --> B["cv2 binding"]
    B --> C["OpenCV C++ core"]
    C --> H["CPU, SIMD, threads"]

Python calls the cv2 binding, which calls compiled C++ that does the heavy lifting.

Because the heavy loops run in compiled code, a call such as cv2.GaussianBlur on a big photo is far faster than a Python loop doing the same math. Bindings also exist for Java, JavaScript and others, and the C++ API is available directly if you need it.

The library is split into modules. You will meet these names again and again:

Module What it holds
core The basic array type, math and drawing support
imgproc Filtering, thresholding, geometry, contours
imgcodecs Reading and writing image files
videoio Cameras and video files
highgui Simple windows for showing images
features2d Keypoints, descriptors and matching
calib3d Camera calibration and 3D geometry
objdetect Cascades, QR codes, ArUco markers
dnn Running trained neural networks

A separate contrib package adds experimental extras, such as some extra trackers and the aruco helpers in older versions. This course uses the 4.x series, the stable line you get from pip today.

One important fact about this course

The real cv2 module needs a native library and, for windows or cameras, a real operating system. A web page cannot give you that, so every cv2 call in this course is shown in read-only code blocks. You copy those onto your own computer (the next lesson shows how to install OpenCV).

That does not mean you only read. OpenCV images are plain NumPy arrays, so almost every idea can be shown live with NumPy alone, and we also re-implement the core algorithms (grayscale, thresholding, convolution, Hough voting, and so on) so you can see exactly what the library does inside. Every lesson says clearly which part is real OpenCV and which part is a stand-in.

Here is the first stand-in. It builds a tiny "image" as an array and prints it as text, one character per pixel, darker pixels as spaces and brighter ones as denser symbols.

Python An image is a grid of numbers

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice the shape: 6 rows and 12 columns. Rows come first, a convention that causes many bugs; we will return to it in Images Are NumPy Arrays.

A tiny vision pipeline

Real vision programs usually follow one pattern: load, convert, process, measure, output. The next stand-in runs that whole pattern on a synthetic scene with two bright squares. It "thresholds" the picture (a step you will meet properly in the Image Processing chapter) and counts how many pixels are bright.

Python Load, process, measure

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The real OpenCV version replaces the comparison with cv2.threshold and the printing with cv2.imshow, but the shape of the program is identical.

The numpy lines here are the genuine mechanism: OpenCV's thresholding is literally a comparison over every pixel, just in optimized C++.

Where OpenCV fits

OpenCV is not a machine-learning framework like PyTorch, and it is not an image editor like Photoshop. It sits in between: it is excellent at classic, hand-built vision (filters, geometry, matching) and it can also run neural networks that someone else trained. Many production systems mix both: classic steps to prepare or crop an image, a neural network to decide what is in it.

If you know a little NumPy, you are ahead. If not, What Is NumPy? is a good short detour, because every OpenCV image you will ever handle is a NumPy array.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the OpenCV core library written in?

    The core is C++ for speed. Python, Java and other languages use bindings that call into it.
  2. 2. In Python, which module do you import to use OpenCV?

    The binding is named cv2 for historical reasons, even though the library is in the 4.x series.
  3. 3. Why are the cv2 calls in this course shown as read-only code?

    OpenCV needs native code (and often windows or cameras). NumPy can show the same ideas live because images are arrays.
  4. 4. Which module would you look in for blurring and thresholding?

    imgproc holds filtering, thresholding, geometry and contours.

Summary

  • OpenCV is an open-source computer-vision library with a fast C++ core and bindings for Python and other languages.
  • In Python you use the cv2 module; the library is organized into modules such as imgproc, videoio and dnn.
  • Real cv2 code is read-only in this course; NumPy stand-ins run live and show how each algorithm works inside.
  • A typical program loads an image, converts it, processes it, measures something and outputs a result.

Next, put OpenCV on your own machine: Installing OpenCV.