Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
Introduction to OpenCV
OpenCV (Open Source Computer Vision Library) is the foundation of most Python Computer Vision projects. Understanding how it represents and works with images is essential.
What is OpenCV?
OpenCV stands for Open Source Computer Vision Library. It was originally developed by Intel in 1999 and is now maintained by the OpenCV Foundation.
Key facts about OpenCV:
- Written in C++ for speed, with Python, Java, and JavaScript bindings
- More than 2,500 optimised algorithms for image and video processing
- Used by Google, Microsoft, Intel, IBM, and thousands of other companies
- Free and open-source under the Apache 2 licence
- The Python package is imported as cv2
OpenCV handles everything from loading a JPG file to running real-time object detection on a live camera feed.
Machine Learning follows a structured pipeline from data to deployment
OpenCV Basics
import cv2
import numpy as np
# OpenCV uses BGR channel order (important!)
# Blue=0, Green=1, Red=2
# Core functions you will use constantly:
# cv2.imread() — load an image from disk
# cv2.imwrite() — save an image to disk
# cv2.imshow() — display an image (desktop apps)
# cv2.cvtColor() — convert between colour spaces
# cv2.resize() — resize an image
# cv2.split() — split into individual channels
# cv2.merge() — combine channels into one image
# Check the OpenCV version
print("OpenCV version:", cv2.__version__)
# Check build information (shows what features are enabled)
# print(cv2.getBuildInformation())
# Create a blank colour image: 300 wide, 200 tall, 3 channels
blank = np.zeros((200, 300, 3), dtype=np.uint8)
print("Blank image shape:", blank.shape)
print("All pixels are black (0,0,0):", blank.sum() == 0)