Simple tools to generate controlnet mask images using OpenCV:
- canny
- depth (fake depth)
- eye_mask
- face_mask
- laplace
- sobel
- soft edge
Deps: opencv-dev
Build with cmake in build/ directory, then run binaries from build/.
cmake . -B build
cmake --build build
The project provides several CLI tools for image processing (edge detection, masks). All tools use unified arguments: -i/--input and -o/--output are required. Run with --help for full usage.
Canny edge detection.
Flags:
-i, --input
: String, required, input image.-o, --output
: String, required, output edge map.-l, --low-threshold
: int, optional, default 100, Canny low threshold.-h, --high-threshold
: int, optional, default 200, Canny high threshold.-b, --blur
: int, optional, default 0, blur kernel size.--help
: Print usage.
Example:
./build/canny_cli -i input.jpg -o edges.png -b 3 -l 50 --high-threshold 150
Fake depth map generation.
Flags:
-i, --input
: String, required.-o, --output
: String, required.-b, --blur
: int, optional, default 0.--help
: Print usage.
Example:
./build/depth_cli --input input.jpg -o depth.png -b 1
Eye detection and masking.
Flags:
-i, --input
: String, required.-o, --output
: String, required.-s, --scale
: float, optional, default 1.1, detection scale.-n, --min-neighbors
: int, optional, default 3.-z, --min-size
: int, optional, default 30.--help
: Print usage. (Also supports -h for help.)
Example:
./build/eye_mask_cli -i face.jpg --output eyes_mask.png -s 1.2 -n 5 -z 40
Face detection and masking.
Flags:
-i, --input
: String, required.-o, --output
: String, required.-s, --scale
: float, optional, default 1.1.-n, --min-neighbors
: int, optional, default 3.-z, --min-size
: int, optional, default 80.-c, --cascade
: string, optional, default built-in, cascade file.-p, --shape
: string, optional, default "oval", shape (oval/rectangle).--help
: Print usage.
Example:
./build/face_mask_cli -i group.jpg -o faces_mask.png --shape rectangle -c haarcascade_frontalface_alt.xml
Laplace edge detection.
Flags:
-i, --input
: String, required.-o, --output
: String, required.-k, --ksize
: int, optional, default 3, kernel size.-b, --blur
: int, optional, default 0.--help
: Print usage.
Example:
./build/laplace_cli --input img.jpg -o laplace_edges.png -k 5 -b 0
Sobel edge detection.
Flags:
-i, --input
: String, required.-o, --output
: String, required.-x, --dx
: int, optional, default 1, dx order.-y, --dy
: int, optional, default 1, dy order.-k, --ksize
: int, optional, default 3, kernel size.-b, --blur
: int, optional, default 0.--scale
: float, optional, default 1.0, scale factor.--delta
: float, optional, default 0.0, delta value.--help
: Print usage.
Example:
./build/sobel_cli -i img.jpg --output sobel.png --dx 1 --dy 1 -k 3
Soft edge detection using Difference of Gaussians.
Flags:
-i, --input
: String, required.-o, --output
: String, required.-b, --blur
: int, optional, default 0.--sigma
: float, optional, default 1.0, sigma for DoG.--help
: Print usage.
Example:
./build/soft_edge_cli -i soft.jpg -o soft_edges.png -b 7 --sigma 2.0
For controlnet models see: https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/tree/main stable diffusion cpp compatible models: https://huggingface.co/lllyasviel/ControlNet-v1-1/tree/459bf90295ac305bc3ae8266e39a089f433eab4f