A console/terminal demo of OpenCV 2D convolution with cv2.filter2D, supporting Windows 11 and Ubuntu Linux 24.04. The input is convolved with a normalized all-ones (box) kernel at several sizes, the classic smoothing kernel, 5×5 and 13×13 by default. A convolution slides the kernel over the image and replaces each pixel with the weighted average of the pixels it covers. Two example images ship under data/ (Lena and sample), and the results are saved to model/filter2d/. 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 and sample.png.
  • model/filter2d/: the results filter2d_5x5.png and filter2d_13x13.png; the Lena examples are included.
  • tool/tools.py: shared helpers.
  • src/: the demo, the launcher scripts and this document.
  • venv/: Python virtual environment, created by step 01.

[Prerequisites]

  • Operating system: Windows 11 or Ubuntu Linux 24.04.
  • Python 3 and pip.
  • No GPU required; an ordinary CPU is enough.

[Instructions]

Step 1: Create the virtual environment

Delete the old venv/, create a fresh one and install the packages listed in src/requirements.txt. The script aborts loudly if pip fails.

 

Windows: src\01_venv_create.bat

Linux: bash src/01_venv_create.sh

Step 2: Activate the virtual environment

Activate the venv. On Linux, source the script.

 

Windows: src\02_venv_activate.bat

Linux: source src/02_venv_activate.sh

Step 3: Run the filter2D demo

Run the convolution demo. Any extra arguments are forwarded to the program.

 

Windows: src\03_filter2d.bat

Linux: bash src/03_filter2d.sh

To use your own image and kernels, for example:

bash src/03_filter2d.sh --source data/sample.png --kernel-sizes 3,9,21

 

Step 4: Remove the virtual environment

Delete the venv/ folder.

 

Windows: src\99_venv_clear.bat

Linux: bash src/99_venv_clear.sh

[Python Entry Point]

  • src/filter2d.py: [--source IMG] [--kernel-sizes 5,13] [--output-dir DIR] [--show]. The defaults are normalized all-ones kernels of 5×5 and 13×13, with ddepth set to -1 so the output keeps the input data type. --kernel-sizes takes a comma-separated list, and the program writes one filter2d_NxN.png per size to model/filter2d/; --show also opens the results in windows. Larger kernels smooth harder.

[References]

 

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.