50 lines
1.1 KiB
Python
50 lines
1.1 KiB
Python
import sys
|
|
|
|
import cv2
|
|
from cv2 import aruco
|
|
|
|
# Define the ArUco dictionary
|
|
aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_4X4_50)
|
|
aruco_params = cv2.aruco.DetectorParameters()
|
|
|
|
# Specify the RTSP URL
|
|
# rtsp_url = sys.argv[1]
|
|
|
|
# webcam:
|
|
cap = cv2.VideoCapture(0)
|
|
|
|
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
|
|
# frame = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5)
|
|
|
|
# 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()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
pass
|