This repository contains example Python scripts used while learning OpenCV (computer vision) concepts. The project is organized into phases with simple, focused scripts demonstrating basic image I/O, transformations, drawing, and text overlay.
read.py— (root) basic image read/display helper used during exercises.phase-1/Assignment-1.py— assignment from phase 1dimensions.py— prints image dimensionsdisplaying.py— demonstrates reading and showing imagesgrayscale.py— convert images to grayscalesaving.py— saving image filestempCodeRunnerFile.py— temporary helper created by editor
phase-2/cropped.py— crop an image regionflipped.py— flip image horizontally/verticallyresizing.py— resize images while keeping aspect ratiorotation.py— rotate images around center
phase-3/add_text.py— overlay text on imagesassignment-3.py— assignment from phase 3draw_circle.py— draw circles on imagesdraw_line.py— draw linesdraw_rect.py— draw rectangles
- Python 3.8+ recommended
- Install dependencies from
requirements.txt(example below)
Create and activate a virtual environment, then install requirements:
# macOS / zsh example
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtIf you're not using a virtualenv, you can run pip install -r requirements.txt directly, but virtual environments are recommended.
- Read and display an image (example):
python read.py- Run a phase script, for example to convert an image to grayscale:
python phase-1/grayscale.pyNotes:
- Many scripts use
cv2.imshow()which opens a GUI window. On headless systems (or some macOS setups), you may need to use an alternative display (like saving output images and opening them) or usematplotlibfor inline displays in notebooks. - If you see a window appear and scripts exit immediately, ensure the code calls
cv2.waitKey(0)andcv2.destroyAllWindows()(many examples include those).
- These scripts are compact learning examples. If you plan to reuse them as utilities, consider moving common operations (load/save/display) into a small helper module.
- Add tests or small sample images in a
data/folder for reproducible runs.
This repository does not currently include a license file.