import numpy as np import numpy.typing as npt import cv2 import uz_framework.image as uz_image from matplotlib import pyplot as plt VIDEO_PATH = "./datam/raw_recording.webm" MY_SIFT = False def start_realtime_keypoint_detection(): # Read video cap = cv2.VideoCapture(VIDEO_PATH) count = 0 sift = cv2.SIFT_create() while cap.isOpened(): ret,frame = cap.read() frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY) # Convert to grayscale if MY_SIFT: #sift_keypoints,_ = uz_image.hessian(frame) _, sift_keypoints = uz_image.hessian_points(frame, 3, 0.004) sift_keypoints = np.float64(sift_keypoints) kps = [] for keypoint in sift_keypoints: y, x = keypoint kps.append(cv2.KeyPoint(x=x, y=y, size=1)) else: kps, _ = sift.detectAndCompute(frame, None) frame = cv2.drawKeypoints(frame, kps, None, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) #cv2.imshow('hello', frame) cv2.imwrite("./datam/true_sift/%d.jpg" % count, frame) print(f'{count} <- frame') count = count + 1 #if cv2.waitKey(10) & 0xFF == ord('q'): #break cap.release() cv2.destroyAllWindows() # destroy all opened windows if __name__ == '__main__': start_realtime_keypoint_detection()