forked from UTSAVS26/PyVerse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
45 lines (34 loc) · 1.3 KB
/
Main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import cv2
def main():
# Initialize the video capture object
cap = cv2.VideoCapture(0) # Change to 0 for default webcam, or provide a video file path
# Initialize ORB detector
orb = cv2.ORB_create()
# Create Brute-Force Matcher
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
while True:
# Capture frame-by-frame
ret, frame = cap.read()
if not ret:
print("Failed to grab frame")
break
# Convert the frame to grayscale
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Detect ORB keypoints and descriptors in the frame
keypoints, descriptors = orb.detectAndCompute(gray, None)
# Check if descriptors are found
if descriptors is not None:
# Draw keypoints on the frame
frame_with_keypoints = cv2.drawKeypoints(frame, keypoints, None, color=(0, 255, 0), flags=0)
else:
frame_with_keypoints = frame
# Display the frame with keypoints
cv2.imshow("Feature Detection", frame_with_keypoints)
# Break the loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release the capture and close any OpenCV windows
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
main()