Console/terminal demo of resizing an image with OpenCV, supporting Windows 11 and Ubuntu Linux 24.04. cv2.resize changes the image to the size you ask for, and the interpolation method decides how the new pixel values are worked out: nearest, linear, area, cubic or lanczos4. As a rule of thumb, use area when shrinking and cubic or lanczos4 when enlarging. Three example images ship under data/ and the result is saved to model/resize/. No GPU is involved.
[Folder Structure]
- CLAUDE.md / AGENT.md: program specification (identical content).
- CHANGELOG.md: change log.
- copyright.txt: copyright notice.
- data/: the example images Lena.png (the notebook's example), SC-150.png and sample.png.
- model/resize/: the result resize.png (ships with the Lena example).
- tool/tools.py: shared helpers.
- src/: the demo, the launcher scripts and this document.
- venv/: Python virtual environment, created by step 1.
[Prerequisites]
- Operating system: Windows 11 or Ubuntu Linux 24.04.
- Python 3 and pip.
- Dependencies are listed in src/requirements.txt and installed by step 1.
- No GPU required.
[Instructions]
Step 1: create the virtual environment
Delete the old venv/, create a fresh one and install src/requirements.txt. Aborts loudly if pip fails.
Windows 11: src\01_venv_create.bat
Ubuntu 24.04: bash src/01_venv_create.sh
Step 2: activate the virtual environment
Activate the venv you just created. On Linux, source it so the environment variables apply to the current shell.
Windows 11: src\02_venv_activate.bat
Ubuntu 24.04: source src/02_venv_activate.sh
Step 3: run the resize demo
Resize the image to the requested size and save the result. Extra arguments are forwarded to the Python script.
Windows 11: src\03_resize.bat
Ubuntu 24.04: bash src/03_resize.sh
Your own image and size:
bash src/03_resize.sh --source data/sample.png --width 256 --height 256 --interpolation lanczos4
Step 4: clear the virtual environment (optional)
Delete the venv/ folder to free disk space when you no longer need it.
Windows 11: src\99_venv_clear.bat
Ubuntu 24.04: bash src/99_venv_clear.sh
[Python Entry Point]
- src/resize.py: [--source IMG] [--width 100] [--height 100] [--interpolation nearest|linear|area|cubic|lanczos4] [--output-dir DIR] [--show].
- --source: input image, default data/Lena.png.
- --width / --height: the target size, default 100 × 100 (the notebook's values).
- --interpolation: the interpolation method, default cubic. Use area when shrinking and cubic or lanczos4 when enlarging; nearest is the fastest but leaves visible jagged edges.
- --output-dir: output folder, default model/resize/. --show also opens the result in a window.
- Saves resize.png and prints the size change.
[References]
- OpenCV geometric transformations tutorial (resize): docs.opencv.org/4.x/da/d6e/tutorial_py_geometric_transformations.html
This SDK is built in AppForAI - AI Dev Tools.
Purchase license separately: USD 600, permanent authorization, single APP authorization, single machine authorization, one-year activation, one-year download, one-year update, one-year email technical support.