赞
踩
import cv2 as cv
import numpy as np
# 创建
dictionary = cv.aruco.getPredefinedDictionary(dict=cv.aruco.DICT_6X6_250)
img = cv.aruco.drawMarker(dictionary, id=23, sidePixels=200, borderBits=1)
# id 指定该Marker在字典中的索引ID,该例中合法的ID为[0, 249]
# sidePixels 指定输出的Marker图像的尺寸,单位是像素,该例中为(200,200)
# 如果使用DICT_6X6_250,则编码区域被划分为6X6个等大小的模块
# 参数borderBits=1,所以整个标志块区域被划分为8X8个等大小的模块
# 模块的尺寸必须大于一个像素。因此该例中,此参数最小值为8
# borderBits 指定编码区域到标志块区域的距离。单位是编码模块。取值必须大于等于1
print(img.shape)
cv.imshow("Aruco Marker", img)
cv.waitKey()
# 创建图像
img_detected = np.ones((800, 600), dtype=np.uint8) * 255
img_detected[50:100, 50:100] = cv.aruco.drawMarker(dictionary, id=23, sidePixels=50, borderBits=1)
img_detected[350:400, 350:400] = cv.aruco.drawMarker(dictionary, id=18, sidePixels=50, borderBits=1)
img_detected[450:500, 450:500] = cv.aruco.drawMarker(dictionary, id=33, sidePixels=50, borderBits=1)
cv.imshow("img_detected", img_detected)
cv.waitKey()
corners, ids, rejectedImgPoints = cv.aruco.detectMarkers(image=img_detected,
dictionary=dictionary,
parameters=None)
img_color = cv.cvtColor(img_detected, cv.COLOR_GRAY2BGR)
cv.aruco.drawDetectedMarkers(img_color, corners, ids)
cv.imshow("DectectedMarker", img_color)
cv.waitKey()
camera_matrix = np.array([[532.79536562, 0, 342.4582516],
[0, 532.91928338, 233.90060514],
[0, 0, 1.]])
dist_coefs = np.array([-2.81086258e-01, 2.72581018e-02, 1.21665908e-03, -1.34204275e-04, 1.58514022e-01])
rvecs, tvecs, _objPoints = cv.aruco.estimatePoseSingleMarkers(corners, 0.05, camera_matrix, dist_coefs)
for i in range(len(rvecs)):
cv.aruco.drawAxis(img_color, camera_matrix, dist_coefs, rvecs[i], tvecs[i], 0.05)
cv.imshow("Pose Estimation", img_color)
cv.waitKey()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。