Spaces:
Running
Running
File size: 616 Bytes
6ba5875 c74a070 6ba5875 c74a070 6ba5875 c74a070 6ba5875 c74a070 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import torch
import cv2
import numpy as np
from PIL import Image
from DeDoDe import dedode_detector_L
def draw_kpts(im, kpts):
kpts = [cv2.KeyPoint(x, y, 1.0) for x, y in kpts.cpu().numpy()]
im = np.array(im)
ret = cv2.drawKeypoints(im, kpts, None)
return ret
detector = dedode_detector_L(weights=torch.load("dedode_detector_l.pth"))
im_path = "assets/im_A.jpg"
im = Image.open(im_path)
out = detector.detect_from_path(im_path, num_keypoints=10_000)
W, H = im.size
kps = out["keypoints"]
kps = detector.to_pixel_coords(kps, H, W)
Image.fromarray(draw_kpts(im, kps[0])).save("demo/keypoints.png")
|