Skip to content

Commit

Permalink
fixed aruco to run on new opencv
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephSaliba01 committed Aug 12, 2024
1 parent 2844fb5 commit 1c42b01
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions camera_data/src/aruco.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
import numpy as np

def main():
# Import aruco after cv2
from cv2 import aruco

# Load the ArUco dictionary and parameters
aruco_dict = cv2.aruco.Dictionary_get(cv2.aruco.DICT_4X4_100)
parameters = cv2.aruco.DetectorParameters_create()
aruco_dict = aruco.getPredefinedDictionary(aruco.DICT_4X4_100)
parameters = aruco.DetectorParameters()
detector = cv2.aruco.ArucoDetector(aruco_dict, parameters)

# Open the video capture (0 for the default camera, or provide a video file path)
cap = cv2.VideoCapture(0)
cap = cv2.VideoCapture(1)

if not cap.isOpened():
print("Error: Could not open video capture.")
Expand All @@ -24,10 +28,9 @@ def main():
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Detect ArUco markers
corners, ids, rejectedImgPoints = cv2.aruco.detectMarkers(gray, aruco_dict, parameters=parameters)
corners, ids, rejectedImgPoints = detector.detectMarkers(frame)

# Draw detected markers
frame_markers = cv2.aruco.drawDetectedMarkers(frame, corners, ids)
if ids is not None:
frame_markers = cv2.aruco.drawDetectedMarkers(frame, corners, ids, borderColor=(0, 255, 0)) # Green border

Expand All @@ -36,7 +39,7 @@ def main():
# Calculate text position
x, y = int(corners[i][0][0][0]), int(corners[i][0][0][1])
text = f"ID: {marker_id}"

# Put text on the frame with red color
cv2.putText(frame_markers, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2, cv2.LINE_AA)
else:
Expand All @@ -55,4 +58,3 @@ def main():

if __name__ == "__main__":
main()

0 comments on commit 1c42b01

Please sign in to comment.