Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cv2.aruco.detectMarkers doesn't detect markers in python

My camera calibration and distortion matrixes, obtained from aruco_calibration_fromimages.exe:

 [[3.19439125e+03   0.00000000e+00   1.98509417e+03]  
  [0.00000000e+00   3.20213561e+03   1.55099552e+03]  
  [0.00000000e+00   0.00000000e+00   1.00000000e+00]]

 [[0.1395281  -0.38313647  0.00505558  0.00237535  0.33952515]]

Image, where I try to detect:

enter image description here

aruco_simple.exe succeeds

enter image description here

But python code fails to find anything:

fs = cv2.FileStorage("./calib_asus_chess/cam_calib_asus.yml", cv2.FILE_STORAGE_READ)
cam_mat=fs.getNode("camera_matrix").mat()
dist_mat=fs.getNode("distortion_coefficients").mat()
gray=cv2.imread('C:\\Users\\steve\\Dropbox\\Projects\\kinnekt\\laser\\aruco_frames\\shot1.jpg',0)
adict = cv2.aruco.Dictionary_get(cv2.aruco.DICT_ARUCO_ORIGINAL)
res = cv2.aruco.detectMarkers(gray,dictionary=adict,cameraMatrix=cam_mat,distCoeff=dist_mat)

res[0] is empty array for some reason. Why python version fails? Thanx!

like image 769
Stepan Yakovenko Avatar asked Dec 20 '17 05:12

Stepan Yakovenko


1 Answers

You are probably using a dictionary that does not correspond to your image. According to the documentation cv2.aruco.DICT_ARUCO_ORIGINAL is 5x5:

DICT_ARUCO_ORIGINAL: standard ArUco Library Markers. 1024 markers, 5x5 bits, 0 minimum distance

Your image has 6x6 icons instead of 5x5, this is why it doesn't work.

You could use the function drawMarker() to draw some markers of the dictionary in an image and then print them and use them for your test.

For example, here you can download DICT_4X4_50 icons. You can print them and change your code to use DICT_4X4_50 instead of DICT_ARUCO_ORIGINAL

like image 70
user2518618 Avatar answered Sep 30 '22 13:09

user2518618