Console/terminal demo of the OpenCV Laplacian edge detector, supporting Windows 11 and Ubuntu Linux 24.04. The input is smoothed with a Gaussian blur, converted to grayscale, and run through cv2.Laplacian. The Laplacian is a second-derivative operator and is quite sensitive to noise, so blurring first keeps noise from being read as an edge. Its output contains both positive and negative values, so it is computed in signed 16-bit and then taken back to an 8-bit image with cv2.convertScaleAbs. Three example images ship under data/ and the results are saved to model/laplace/. 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/laplace/: the results gray.png and laplace.png (ship with the Lena examples).
  • 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 Laplacian edge demo

Blur, convert to grayscale, run the Laplacian and save the results. Extra arguments are forwarded to the Python script.

 

Windows 11: src\03_laplace.bat

Ubuntu 24.04: bash src/03_laplace.sh

Your own image and parameters:

bash src/03_laplace.sh --source data/SC-150.png --blur-kernel 5 --ksize 5

 

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/laplace.py: [--source IMG] [--blur-kernel 17] [--ksize 3] [--scale 1] [--delta 0] [--output-dir DIR] [--show].
  • --source: input image, default data/Lena.png.
  • --blur-kernel: the Gaussian blur kernel size, default 17 (17x17, the notebook's value). Lower it to keep more detail, at the cost of more noise.
  • --ksize: the Laplacian kernel size, default 3. Raise it for thicker, more prominent edges.
  • --scale / --delta: the scale factor and the offset applied to the output, default 1 and 0.
  • --output-dir: output folder, default model/laplace/. --show also opens the results in windows.
  • Both kernel sizes must be odd (validated).
  • Saves gray.png (grayscale) and laplace.png (the edge result).

[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.