This repository contains a phase-by-phase OpenCV learning course built in Python. Each script focuses on one concept, from reading images and drawing shapes to webcam capture, image filtering, contour detection, and face/expression detection.
- Loading, displaying, inspecting, and saving images
- Image transformation and manipulation: resize, crop, rotate, flip
- Basic drawing on images: lines, rectangles, circles, and text
- Webcam capture and video recording/playback
- Image filtering: Gaussian blur, median blur, sharpening
- Edge detection, thresholding, and bitwise operations
- Contour detection and shape classification
- Face, eye, and smile detection with Haar cascades
- Python 3.x
opencv-contrib-python
Install dependencies with:
pip install -r requirements.txtComputer Vision/
├── Phase 1 - Working with Images/
├── Phase 2 - Image Transformation & Manipulation/
├── Phase 3 - Basic Image Drawing Techniques/
├── Phase 4 - Working with Video & Webcam/
├── Phase 5 - Image Filtering & Blurring/
├── Phase 6 - Edge Detection & Thresholding/
├── Phase 7 - Contours & Shape Detection/
├── Phase 8 - Face & Object Detection/
├── Source/
├── output/
├── requirements.txt
└── README.md
These scripts introduce the basics of OpenCV image handling.
1.reading.pyloadsinput_img.pngand checks whether the file was read successfully.2.showing.pydisplays the loaded image in a window.3.b&w.pyconverts the image to grayscale.4.shape.pyprints the image dimensions as height, width, and channels.5.write.pysaves the image asoutput_img.png.6.Assignment_1.pyis an interactive exercise that loads an image, converts it to grayscale, and lets the user show, save, or do both.
These scripts demonstrate how to alter the size and orientation of an image.
1.resizing.pyresizes the image to1300 x 600and saves the result asresized_img.png.2.cropping.pycrops a rectangular region from the image and saves it ascropped_img.png.3.rotation.pyrotates the image by several angles and also demonstrates scaling.4.flipping.pyflips the image vertically.
These scripts show how to draw on top of an image using OpenCV primitives.
1.line.pydraws a blue line.2.rectangle.pydraws a green rectangle.3.circle.pydraws a filled red circle.4.text.pywrites text on the image.5.Assignment_2.pyis an interactive exercise where the user chooses a shape or text, enters coordinates, and then shows or saves the modified image.
This phase introduces webcam capture and video I/O.
1.videoCapture.pyopens the webcam and streams live video.2.saving.pyrecords webcam video tooutput_feed.avi.3.Assignment_3.pyis an interactive script with three modes: live webcam display, record webcam video to a custom path, or play back a video file.
These scripts demonstrate common filters used for smoothing and sharpening.
1.gaussian_blur.pyapplies Gaussian blur.2.median_blur.pyapplies median filtering for noise removal.3.sharpening.pyapplies a sharpening kernel.
These scripts focus on extracting structure from images.
1.canny_edge_detection.pydetects edges using the Canny algorithm.2.thresholding.pyconverts a grayscale image into a binary image.3.bitwise_operation.pydemonstrates bitwise AND, OR, XOR, and NOT on synthetic shapes.
These scripts work with object outlines and shape classification.
1.finding_contours.pyfinds and draws contours on a thresholded image.2.shape_detection.pydetects contours, approximates polygon vertices, and labels shapes such as triangle, rectangle, pentagon, and circle.
This phase uses Haar cascades for real-time object detection.
1.face_detection.pydetects faces from the webcam feed.2.expression_detection.pydetects faces, eyes, and smiles and adds labels to the video stream.
Several scripts expect sample images in the project root:
input_img.pngfor most Phase 1 to Phase 6 scriptstriangle.pngforPhase 7 - Contours & Shape Detection/1.finding_contours.pycircle.pngforPhase 7 - Contours & Shape Detection/2.shape_detection.py
If those files are not present, the scripts will print an error or fail to load the image.
Generated files are written either to the project root or to the output/ folder, depending on the script.
Common outputs include:
output_img.pngresized_img.pngcropped_img.pngoutput_feed.avi
The face-detection scripts use the XML classifiers stored in Source/:
Source/haarcascade_frontalface_default.xmlSource/haarcascade_eye.xmlSource/haarcascade_smile.xml
If you run the scripts from the project root, make sure the cascade paths in the code match the file location. If needed, update the script paths to point to the Source/ folder.
Run any script directly with Python. For example:
python "Phase 1 - Working with Images/1.reading.py"
python "Phase 4 - Working with Video & Webcam/1.videoCapture.py"Some scripts are interactive and will ask for input in the terminal, such as:
- image path
- output file name
- coordinates for drawing
- webcam vs file playback mode
- Most scripts are intentionally small and independent so each concept can be tested on its own.
- Webcam-based scripts require a working camera and may need permission access depending on your system.
- Video recording uses the
XVIDcodec, which is commonly supported on Windows.
- Phase 1: Learn how OpenCV reads, shows, and saves images.
- Phase 2: Practice resizing, cropping, rotating, and flipping.
- Phase 3: Draw shapes and text on images.
- Phase 4: Move to webcam and video processing.
- Phase 5: Apply blurring and sharpening filters.
- Phase 6: Detect edges and separate foreground with thresholding.
- Phase 7: Detect contours and classify shapes.
- Phase 8: Detect faces and facial features in real time.