uz_assignments/assignment4/cam.py

41 lines
1.3 KiB
Python
Raw Permalink Normal View History

2022-11-29 19:30:39 +01:00
import numpy as np
import numpy.typing as npt
2022-11-28 15:47:06 +01:00
import cv2
2022-11-29 19:30:39 +01:00
import uz_framework.image as uz_image
from matplotlib import pyplot as plt
2022-11-28 15:47:06 +01:00
2022-11-30 16:15:07 +01:00
VIDEO_PATH = "./datam/raw_recording.webm"
2022-11-30 22:54:39 +01:00
MY_SIFT = False
2022-11-28 15:47:06 +01:00
2022-11-30 16:15:07 +01:00
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:
2022-11-30 18:51:31 +01:00
#sift_keypoints,_ = uz_image.hessian(frame)
_, sift_keypoints = uz_image.hessian_points(frame, 3, 0.004)
2022-11-30 16:15:07 +01:00
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)
2022-11-30 22:54:39 +01:00
cv2.imwrite("./datam/true_sift/%d.jpg" % count, frame)
2022-11-30 18:51:31 +01:00
print(f'{count} <- frame')
2022-11-30 16:15:07 +01:00
count = count + 1
#if cv2.waitKey(10) & 0xFF == ord('q'):
#break
2022-11-28 15:47:06 +01:00
cap.release()
2022-11-30 16:15:07 +01:00
cv2.destroyAllWindows() # destroy all opened windows
2022-11-28 15:47:06 +01:00
if __name__ == '__main__':
2022-11-29 19:30:39 +01:00
start_realtime_keypoint_detection()