2024-03-04 17:50:28 +00:00
|
|
|
from kornia.filters import canny
|
2024-05-27 23:03:56 +00:00
|
|
|
import comfy.model_management
|
2023-07-13 17:26:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Canny:
|
|
|
|
@classmethod
|
|
|
|
def INPUT_TYPES(s):
|
|
|
|
return {"required": {"image": ("IMAGE",),
|
|
|
|
"low_threshold": ("FLOAT", {"default": 0.4, "min": 0.01, "max": 0.99, "step": 0.01}),
|
|
|
|
"high_threshold": ("FLOAT", {"default": 0.8, "min": 0.01, "max": 0.99, "step": 0.01})
|
|
|
|
}}
|
|
|
|
|
|
|
|
RETURN_TYPES = ("IMAGE",)
|
|
|
|
FUNCTION = "detect_edge"
|
|
|
|
|
|
|
|
CATEGORY = "image/preprocessors"
|
|
|
|
|
|
|
|
def detect_edge(self, image, low_threshold, high_threshold):
|
2023-08-29 21:58:40 +00:00
|
|
|
output = canny(image.to(comfy.model_management.get_torch_device()).movedim(-1, 1), low_threshold, high_threshold)
|
2023-12-08 07:35:45 +00:00
|
|
|
img_out = output[1].to(comfy.model_management.intermediate_device()).repeat(1, 3, 1, 1).movedim(1, -1)
|
2023-07-13 17:26:48 +00:00
|
|
|
return (img_out,)
|
|
|
|
|
|
|
|
NODE_CLASS_MAPPINGS = {
|
|
|
|
"Canny": Canny,
|
|
|
|
}
|