import cv2
import cv2.aruco as aruco

# Use the first camera connected to your computer
cap = cv2.VideoCapture(0)  # 0 is typically the default camera


aruco_dict = aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_50)
parameters = aruco.DetectorParameters()

while True:
    ret, frame = cap.read()
    if not ret:
        break
    
    # Convert to grayscale
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    
    # Detect ArUco markers
    corners, ids, rejectedImgPoints = aruco.detectMarkers(gray, 
    aruco_dict, parameters=parameters)

    # Draw detected markers
    aruco.drawDetectedMarkers(frame, corners, ids)

    # Display the resulting frame
    cv2.imshow('Regular', frame)
    cv2.imshow('Gray', gray)
    
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()