Skip to content

Introduction

Here is the first section of the OpenCV learning guide:


📘 1. Introduction to OpenCV

OpenCV (Open Source Computer Vision Library) is a popular open-source toolkit for real-time computer vision applications. It supports Python, C++, and Java, with a rich set of functions for image and video processing.


🔧 1.1 What is OpenCV?

  • A library focused on real-time image processing, object detection, face recognition, and camera calibration.
  • Originally developed by Intel; now maintained by the open-source community.
  • Frequently used in robotics, AR, surveillance, and visual analytics.

📦 1.2 Installation

✅ Python

pip install opencv-python
pip install opencv-python-headless  # if you don't need GUI
pip install opencv-contrib-python   # for extra modules (e.g., SIFT, SURF)

✅ C++

  • Download OpenCV from: https://opencv.org/releases/
  • Use CMake to build and link OpenCV with your C++ project.

🖼️ 1.3 Basic Image Operations

Read, Display, Write an Image (Python)

import cv2

img = cv2.imread('image.jpg')       # Read
cv2.imshow('My Image', img)         # Display
cv2.waitKey(0)
cv2.destroyAllWindows()

cv2.imwrite('output.jpg', img)      # Save

🎞️ 1.4 Basic Video Operations

Read from Webcam

cap = cv2.VideoCapture(0)
while True:
    ret, frame = cap.read()
    if not ret:
        break
    cv2.imshow("Webcam", frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

✅ Summary

Concept Purpose
cv2.imread() Load image
cv2.imshow() Show image in a window
cv2.imwrite() Save image to disk
cv2.VideoCapture() Capture video from webcam or file
cv2.waitKey() Wait for key press (used for control flow)
cv2.destroyAllWindows() Close all OpenCV GUI windows