2023-09-17 15:35:07 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import cv2
|
|
|
|
from cv2 import aruco
|
|
|
|
|
|
|
|
# Define the ArUco dictionary
|
2024-08-11 18:23:47 +00:00
|
|
|
aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_4X4_50)
|
2023-09-17 15:35:07 +00:00
|
|
|
aruco_params = cv2.aruco.DetectorParameters()
|
|
|
|
|
|
|
|
# Specify the RTSP URL
|
2024-08-11 18:23:47 +00:00
|
|
|
# rtsp_url = sys.argv[1]
|
2023-09-17 15:35:07 +00:00
|
|
|
|
2024-08-11 18:23:47 +00:00
|
|
|
# webcam:
|
|
|
|
cap = cv2.VideoCapture(0)
|
2023-09-17 15:35:07 +00:00
|
|
|
|
|
|
|
while True:
|
|
|
|
ret, frame = cap.read()
|
|
|
|
|
|
|
|
# Check if frame is not empty
|
|
|
|
if frame is None:
|
|
|
|
print("Empty frame, exiting...")
|
|
|
|
break
|
|
|
|
|
|
|
|
# Detect ArUco markers
|
|
|
|
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
|
|
|
corners, ids, rejectedImgPoints = aruco.detectMarkers(
|
|
|
|
gray, aruco_dict, parameters=aruco_params
|
|
|
|
)
|
|
|
|
|
|
|
|
# If some markers are found, draw them on the frame
|
|
|
|
if ids is not None:
|
|
|
|
frame = cv2.aruco.drawDetectedMarkers(frame, corners, ids)
|
|
|
|
|
|
|
|
# Scale frame in half
|
2024-08-11 18:23:47 +00:00
|
|
|
# frame = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5)
|
2023-09-17 15:35:07 +00:00
|
|
|
|
|
|
|
# Display the frame
|
|
|
|
cv2.imshow("Frame", frame)
|
|
|
|
|
|
|
|
# Wait for the 'q' key to exit the loop
|
|
|
|
if cv2.waitKey(1) & 0xFF == ord("q"):
|
|
|
|
break
|
|
|
|
|
|
|
|
# Release the capture object and close all OpenCV windows
|
|
|
|
cap.release()
|
|
|
|
cv2.destroyAllWindows()
|
2024-08-11 18:23:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
pass
|