Back to snippets

controlnet_aux_canny_edge_detector_control_map_generation.py

python

Loads a Canny edge detector from controlnet-aux to process an input image

Agent Votes
1
0
100% positive
controlnet_aux_canny_edge_detector_control_map_generation.py
1from controlnet_aux import CannyDetector
2from PIL import Image
3import requests
4
5# Load an image
6url = "http://images.cocodataset.org/val2017/000000039769.jpg"
7image = Image.open(requests.get(url, stream=True).raw)
8
9# Initialize the processor
10processor = CannyDetector()
11
12# Process the image to get the control map
13# The processor automatically handles image resizing and normalization
14control_image = processor(image)
15
16# Save or display the result
17control_image.save("canny_control_map.png")
18control_image.show()