Beginner

Introduction to OpenCV

Discover the world's most popular open-source computer vision library, used by millions of developers for image and video processing.

What is OpenCV?

OpenCV (Open Source Computer Vision Library) is an open-source library of programming functions aimed at real-time computer vision. Originally developed by Intel in 1999, it has become the de facto standard for computer vision tasks with over 2,500 optimized algorithms.

OpenCV supports Python, C++, Java, and JavaScript. It runs on Windows, Linux, macOS, Android, and iOS, making it one of the most versatile CV libraries available.

Core Modules

📸

imgproc

Image processing: filtering, geometric transformations, color space conversions, histograms, and morphological operations.

👁

objdetect

Object detection using Haar cascades, HOG descriptors, and QR/barcode detection.

🎥

videoio

Video capture and writing. Read from cameras, video files, or image sequences.

🧠

dnn

Deep neural network module for running pre-trained models from TensorFlow, PyTorch, ONNX, and Caffe.

Why OpenCV?

FeatureOpenCVPillowscikit-imageTorchVision
SpeedFastest (C++ core)ModerateModerateFast (GPU)
Video SupportExcellentNoneLimitedLimited
Real-timeYesNoNoYes (GPU)
DNN InferenceBuilt-inNoNoBuilt-in
Algorithms2,500+BasicGoodDL-focused
LicenseApache 2.0MIT-likeBSDBSD

A Quick Example

Python — Read and display an image
import cv2

# Read an image
img = cv2.imread("photo.jpg")

# Convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Display the image
cv2.imshow("Grayscale", gray)
cv2.waitKey(0)
cv2.destroyAllWindows()
Key takeaway: OpenCV uses BGR color ordering by default (not RGB). This is a common source of confusion when integrating with other libraries like matplotlib or PIL. Always convert with cv2.cvtColor(img, cv2.COLOR_BGR2RGB) when needed.
💡
Prerequisites: Basic Python knowledge and familiarity with NumPy arrays. OpenCV represents images as NumPy arrays, so understanding array operations is essential.