Current package version:

numpy                 1.25.1
opencv-contrib-python 4.8.0.74
opencv-python         4.8.0.74
import cv2
import numpy as np

# Load the predefined dictionary
dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_250)

# Load the image
image = cv2.imread('path_to_image.jpg')

# Convert the image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Detect the markers in the image
corners, ids, rejectedImgPoints = cv2.aruco.detectMarkers(gray, dictionary)

# Check if any markers were found
if ids is not None:
    # Assume the first detected marker
    marker_corners = corners[0][0]

    # Calculate the area using contour area function
    area = cv2.contourArea(marker_corners.astype('int'))
    print("Area in pixels:", area)
else:
    print("No markers found")

标签: none

评论已关闭