Computer Vision · Python
Computer Vision Projects with Python: Step-by-Step Guide
The fastest way to understand computer vision is to build small projects that each teach one idea. The six projects below go from pure NumPy to pretrained deep learning models. Each one lists what you will learn, the libraries, and the steps; the first is complete code you can run straight away.
Set up
python -m venv cv-env
# activate it, then:
pip install numpy pillow opencv-python ultralyticsnumpy and pillow are enough for Project 1. OpenCV (opencv-python) is the standard library for classical vision, and ultralytics provides pretrained YOLO object detectors.
Project 1 (beginner): edge detection from scratch
You will learn: that an image is just an array of numbers, how a convolution filter works, and how edges are found. This is the idea behind every convolutional neural network.
import numpy as np
from PIL import Image, ImageDraw
# 1. Make a test image: a white square on a dark background (use Image.open("photo.jpg") for a real one)
img = Image.new("RGB", (120, 80), (30, 30, 30))
ImageDraw.Draw(img).rectangle([40, 20, 79, 59], fill=(240, 240, 240))
# 2. Convert to grayscale and to a NumPy array of floats
gray = np.asarray(img.convert("L"), dtype=float)
# 3. Sobel filters for horizontal and vertical changes in brightness
kx = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]])
ky = kx.T
def filter2d(a, k):
out = np.zeros((a.shape[0] - 2, a.shape[1] - 2))
for i in range(3):
for j in range(3):
out += k[i, j] * a[i:i + out.shape[0], j:j + out.shape[1]]
return out
magnitude = np.hypot(filter2d(gray, kx), filter2d(gray, ky))
# 4. Keep only strong edges and save the result
edges = (magnitude > 0.5 * magnitude.max()).astype(np.uint8) * 255
Image.fromarray(edges).save("edges.png")
print("image size:", gray.shape, "| edge map size:", edges.shape)
print("edge pixels found:", int((edges > 0).sum()))Output:
image size: (80, 120) | edge map size: (78, 118)
edge pixels found: 316Open edges.png and you will see the outline of the square. The Sobel filters measure how fast brightness changes horizontally and vertically, np.hypot combines them, and the threshold keeps the strongest changes. Try it on your own photo by replacing step 1 with Image.open("photo.jpg"), then change the 0.5 threshold and watch fine detail appear or disappear. The role of computer vision in AI explains where this step sits in a full vision pipeline.
Project 2 (beginner): face detection from a webcam
You will learn: reading video frames, converting colour spaces, and using a pretrained classical detector (Haar cascade) that ships with OpenCV.
import cv2
face_model = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
camera = cv2.VideoCapture(0) # 0 = default webcam
while True:
ok, frame = camera.read()
if not ok:
break
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_model.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5)
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.imshow("Faces (press q to quit)", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
camera.release()
cv2.destroyAllWindows()A green box follows each detected face. Haar cascades are fast but fail on side profiles and poor light, which is a good way to see why deep-learning detectors replaced them. Tune minNeighbors: higher values mean fewer false detections but more missed faces.
Project 3 (intermediate): document scanner
You will learn: edge detection with cv2.Canny, finding contours, and perspective transforms.
- Load a photo of a page on a desk and convert it to grayscale; blur it slightly with
cv2.GaussianBlurto remove noise. - Run
cv2.Cannyto get edges, thencv2.findContoursto get outlines. - Keep the largest contour that
cv2.approxPolyDPreduces to four corners: that is the page. - Order the corners, compute a transform with
cv2.getPerspectiveTransform, and flatten the page withcv2.warpPerspective. - Optionally threshold the result with
cv2.adaptiveThresholdfor a clean black-and-white scan, and pass it to an OCR engine as in converting an image to text.
Project 4 (intermediate): object detection with a pretrained YOLO model
You will learn: using a modern deep-learning detector without training it yourself, and reading its output (class, confidence, bounding box).
from ultralytics import YOLO
model = YOLO("yolov8n.pt") # small pretrained model, downloaded on first run
results = model("street.jpg") # any photo with people, cars, etc.
for box in results[0].boxes:
label = model.names[int(box.cls)]
print(label, round(float(box.conf), 2))
results[0].save(filename="street_detected.jpg")The script prints each detected object with its confidence and saves an annotated copy of the image. The model was trained on the COCO dataset, so it recognises its 80 everyday classes (people, cars, dogs, cups and so on). The next step is fine-tuning it on your own labelled images, for example helmets on a building site.
Project 5 (intermediate): handwritten digit classifier
You will learn: training a convolutional neural network end to end.
- Load the MNIST dataset of 28 × 28 digit images (it is built into Keras and torchvision).
- Scale pixel values to the range 0–1.
- Build a small CNN: two convolution + pooling blocks, then a dense layer with 10 outputs.
- Train for a few epochs and measure accuracy on the held-out test set, not the training set.
- Draw your own digit, resize it to 28 × 28, and see whether the model reads it. It often fails on thick or off-centre digits, which teaches you about data distribution.
How CNN architecture works explains each layer you use here.
Project 6 (advanced): number plate recognition
You will learn: chaining two models, a detector and a reader, into one system.
- Fine-tune a YOLO model (Project 4) to detect number plates, using a public labelled plate dataset.
- Crop each detected plate and clean it up: grayscale, resize, threshold.
- Read the characters with an OCR library such as EasyOCR or Tesseract.
- Check the result against the expected plate format with a regular expression, and log plates with timestamps.
Test it on photos taken at night and at an angle; handling those cases is most of the real work.
Tips for making these projects count
- Write down what fails, not only what works. Error analysis is what interviewers ask about.
- Measure results on images the model has never seen.
- Put each project on GitHub with a short README, sample inputs and outputs. See machine learning projects for your resume for how to present them.
- Respect privacy: do not collect or publish photos of people without consent.
For the industries where these skills are used, see applications of computer vision. Computer vision projects are part of Uncodemy's Artificial Intelligence course.