Last active
October 30, 2021 22:45
-
-
Save austinbhale/f62cc5e8fd1702a5317929004fa5f4c9 to your computer and use it in GitHub Desktop.
Create an Aruco Board image with Python3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 as cv | |
import numpy as np | |
dictionary = cv.aruco.Dictionary_get(cv.aruco.DICT_6X6_50) | |
num_markers_x = 4 | |
num_markers_y = 4 | |
marker_length = 0.04 | |
marker_separation = 0.01 | |
board = cv.aruco.GridBoard_create( | |
num_markers_x, # Number of markers in the X direction. | |
num_markers_y, # Number of markers in the Y direction. | |
marker_length, # Length of the marker side. | |
marker_separation, # Length of the marker separation. | |
dictionary # The dictionary of the markers. | |
# (optional) Ids of all the markers (X*Y markers). | |
) | |
img = np.zeros((580,580), np.uint8) #4x4 | |
# help(cv.aruco_GridBoard.draw) | |
# draw(outSize[, img[, marginSize[, borderBits]]]) -> img | |
img = board.draw( | |
img.shape, # Size of the output image in pixels. | |
img, # Output image with the board | |
0, # Minimum margins (in pixels) of the board in the output image | |
1 # Width of the marker borders | |
) | |
extension = ".jpg" | |
cv.imwrite("aruco_" + | |
str(num_markers_x) + "x" + str(num_markers_y) + "_" + | |
str(int(marker_length*100)) + "cm_length_" + | |
str(int(marker_separation*100)) + "cm_space" | |
+ extension, img) | |
cv.imshow("aruco_board", img) | |
cv.waitKey(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment