Hi
I would like to know if it is possible to obtain the POSE (RVEC and TVEC) in relation to the center of the Aruco GridBoard. Here is an example image:
here’s a part of my code:
# Check for camera calibration data
#escolher aqui o arqivo de calibracao para a resolucao desejada
calibration_file = "calibration_640_480.pckl"
if not os.path.exists('./calibration_files/'+str(calibration_file)):
print("You need to calibrate the camera you'll be using. See calibration project directory for details.")
exit()
else:
f = open('calibration_files/'+str(calibration_file), 'rb')
(cameraMatrix, distCoeffs, _, _) = pickle.load(f)
f.close()
if cameraMatrix is None or distCoeffs is None:
print("Calibration issue. Remove ./calibration_files/"+str(calibration_file)+" and recalibrate your camera with CalibrateCamera.py.")
exit()
# Constant parameters used in Aruco methods
ARUCO_PARAMETERS = aruco.DetectorParameters_create()
ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_4X4_50)
# Create grid board object we're using in our stream
board = aruco.GridBoard_create(
markersX=2,
markersY=2,
markerLength=0.0615,
markerSeparation=0.0615,
dictionary=ARUCO_DICT)
# Create vectors we'll be using for rotations and translations for postures
rvecs, tvecs = None, None
i = 0
while True:
ret = True
QueryImg = frame
if ret == True:
# grayscale image
#gray = cv2.cvtColor(QueryImg, cv2.COLOR_BGR2GRAY)
# Detect Aruco markers
corners, ids, rejectedImgPoints = aruco.detectMarkers(frame, ARUCO_DICT, parameters=ARUCO_PARAMETERS)
# Refine detected markers
# Eliminates markers not part of our board, adds missing markers to the board
corners, ids, rejectedImgPoints, recoveredIds = aruco.refineDetectedMarkers(
image = frame,
board = board,
detectedCorners = corners,
detectedIds = ids,
rejectedCorners = rejectedImgPoints,
cameraMatrix = cameraMatrix,
distCoeffs = distCoeffs)
# Outline all of the markers detected in our image
QueryImg = aruco.drawDetectedMarkers(QueryImg, corners, borderColor=(0, 0, 255))
#cameraMatrix[0][2]),int(cameraMatrix[1][2] sao o ponto principal da camera e quase a posicao central
QueryImg = cv2.circle(QueryImg,(int(cameraMatrix[0][2]),int(cameraMatrix[1][2])),5,(255,0,0),2)
# Require 15 markers before drawing axis
if ids is not None and len(ids) > 2:
# Estimate the posture of the gridboard, which is a construction of 3D space based on the 2D video
pose, rvec, tvec = aruco.estimatePoseBoard(corners, ids, board, cameraMatrix, distCoeffs)
if pose:
# Draw the camera posture calculated from the gridboard
QueryImg = aruco.drawAxis(QueryImg, cameraMatrix, distCoeffs, rvec, tvec, 0.3)
i=i+1
print('Contagem: ', i)
print('TVEC: ', tvec)
# Display our image
cv2.imshow('QueryImage', QueryImg)
# Exit at the end of the video on the 'q' keypress
if cv2.waitKey(1) & 0xFF == ord('q'):
break
#----------------------------------------------------------------------------------------------------------------------------------------#
cv2.destroyAllWindows()
thanks