Console/terminal demo of grayscale conversion with OpenCV, supporting Windows 11 and Ubuntu Linux 24.04. The image is converted with cv2.cvtColor(img, cv2.COLOR_BGR2GRAY), collapsing the three-channel colour image into a single-channel grayscale image. OpenCV loads images in BGR channel order rather than the more common RGB, so COLOR_BGR2GRAY is the right constant here; using the RGB variant produces slightly different brightness. One example image ships under data/ (lena) and the result is saved to model/gray/. 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 image lena.png (the notebook's example).
- model/gray/: the result gray.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 grayscale demo
Read the image, convert it to grayscale and save the result. Extra arguments are forwarded to the Python script.
Windows 11: src\03_gray.bat
Ubuntu 24.04: bash src/03_gray.sh
Your own image:
bash src/03_gray.sh --source data/lena.png --show
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/gray.py: [--source IMG] [--output-dir DIR] [--show].
- --source: input image, default data/lena.png.
- --output-dir: output folder, default model/gray/.
- --show: also open the result in a window.
- The result is saved as gray.png.
[References]
- OpenCV color conversion tutorial: docs.opencv.org/4.x/df/d9d/tutorial_py_colorspaces.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.