Thanks for your quick response.
I have done this prototype of code, I have not test it because I’m not in the laboratory but I will test it the next week. Could you see something wrong there? Do you think this will work?
def DetectMarkerBoard(self):
"""
Funcion que permite detectar el "tablero" de marcadores ArUco tras obtener los pareametros asociados
a la camara
:return: vector de desalineamientos [X,Y,Z,Rx,Ry,Rz] que determinan la pose del SIROM (TABLERO)
respecto de la camara
"""
cam=cv2.VideoCapture(self.CameraID,cv2.CAP_DSHOW)
#Configuro la camara para la captura del objetivo
cam.set(3, 1280) # width --> Anchura
cam.set(4, 720) # height--> altura
cam.set(39, 0) #Autofocus OFF
start=0
stop=0
ArucoDict = cv2.aruco.Dictionary_get(self.ArucoDict)
ArucoParams = cv2.aruco.DetectorParameters_create()
ArucoParams.cornerRefinementMethod = 1
rvec=None
tvec=None
while True:
ret, frame =cam.read()
Frame_procesado=self.Preproces(frame)
if ret != True:
print("NO HA SIDO POSIBLE RECIBIR NINGUN FRAME DE LA CAMARA")
break
else:
esquinas, ids, rechazados = cv2.aruco.detectMarkers(Frame_procesado, ArucoDict, parameters=ArucoParams,cameraMatrix=self.CamMtx, distCoeff=self.CamDst)
#Convierto las esquinas a X,Y,Z
new_corners = np.zeros(shape=(len(esquinas), 4, 3))
for cnt, corner in enumerate(esquinas):
new_corners[cnt, :, :-1] = corner
# Creo mi board compuesto de dos marcadores
ArucoBoard=cv2.aruco.Board_create(new_corners.astype(np.float32), self.ArucoDict, ids)
if len(esquinas)>0: #En caso de que como minimo 1 marcador detectado
#Detecto el board compuesto de los dos aruco
ret,rvec_Aruco_respect_Camara, tvec_Aruco_respect_Camara=cv2.aruco.estimatePoseBoard(esquinas,ids,ArucoBoard,self.CamMtx,self.CamDst,rvec,tvec)
#Calculo FPS de la camara
stop=time.time()
self.FPS=1/(stop-start)
start=stop
fps="FPS: "+str(int(self.FPS))
if ret>0:
frame=cv2.aruco.drawAxis(Frame_procesado, self.CamMtx, self.CamDst, rvec_Aruco_respect_Camara, tvec_Aruco_respect_Camara, 0.05)
cv2.putText(frame, fps, (3, 25), cv2.FONT_HERSHEY_SIMPLEX, 1, (100, 255, 0), 3, cv2.LINE_AA)
cv2.imshow("SIROM detectado", frame)
cv2.waitKey(1)
else:
#Calculo FPS de la camara, dibujo los ejes de coordenadas, el nÂş de FPS...
stop = time.time()
self.FPS = 1 / (stop - start)
start = stop
fps = "FPS: " + str(int(self.FPS))
cv2.putText(frame, fps, (3, 25), cv2.FONT_HERSHEY_SIMPLEX, 1, (100, 255, 0), 3, cv2.LINE_AA)
cv2.imshow("SIROM detectado", frame)
cv2.waitKey(1)
print("NO SE HA DETECTADO NINGUN SIROM")
It must be said that I calculated the aruco board
in each iteration because the object which have the markers will be moving during the test, so I need to know the aruco points for each iteration and also, calculate the board in each iteration.