import cv2 | |
import torch | |
import numpy as np | |
class CannyDetector: | |
def __call__(self, img, low_threshold=100, high_threshold=200): | |
""" | |
input: array or tensor (H,W,3) | |
output: array (H,W) | |
""" | |
if torch.is_tensor(img): | |
img = img.cpu().detach().numpy().astype(np.uint8) | |
return cv2.Canny(img, low_threshold, high_threshold) | |