| 319 | |
| 320 | |
| 321 | class Image2Canny: |
| 322 | def __init__(self, device): |
| 323 | print("Initializing Image2Canny") |
| 324 | self.low_threshold = 100 |
| 325 | self.high_threshold = 200 |
| 326 | |
| 327 | @prompts(name="Edge Detection On Image", |
| 328 | description="useful when you want to detect the edge of the image. " |
| 329 | "like: detect the edges of this image, or canny detection on image, " |
| 330 | "or perform edge detection on this image, or detect the canny image of this image. " |
| 331 | "The input to this tool should be a string, representing the image_path") |
| 332 | def inference(self, inputs): |
| 333 | image = Image.open(inputs) |
| 334 | image = np.array(image) |
| 335 | canny = cv2.Canny(image, self.low_threshold, self.high_threshold) |
| 336 | canny = canny[:, :, None] |
| 337 | canny = np.concatenate([canny, canny, canny], axis=2) |
| 338 | canny = Image.fromarray(canny) |
| 339 | updated_image_path = get_new_image_name(inputs, func_name="edge") |
| 340 | canny.save(updated_image_path) |
| 341 | print(f"\nProcessed Image2Canny, Input Image: {inputs}, Output Text: {updated_image_path}") |
| 342 | return updated_image_path |
| 343 | |
| 344 | |
| 345 | class CannyText2Image: |
nothing calls this directly
no outgoing calls
no test coverage detected