Ask Your Question
0

display pose next to the the detetcted ArUco marker [closed]

asked 2018-11-17 02:42:38 -0600

Shrijan gravatar image

Hi, I'm able to get pose of all the detected markers but i'm not able to display the pose of each marker respectively on the image.

        for i in range(0, self.ids.size):
            #print(self.tvecs[i][0][2])
            cv_image=aruco.drawAxis(cv_image, camera_matrix, camera_distortion, self.rvecs[i], self.tvecs[i], 10)
            #str_position = "trans"%((self.tvecs[i][0]))

            str_position = "MARKER Position x=%4.0f  y=%4.0f  z=%4.0f"%(self.tvecs[i][0][0], self.tvecs[i][0][1], self.tvecs[i][0][2])
            #cv2.putText(cv_image, str_position, (0, 100), font, 1, (0, 255, 0), 2, cv2.LINE_AA)
            cv2.putText(cv_image, "{:.2f}".format(str_position), (0,100), font, 4,(255,255,255), 2, cv2.LINE_AA)

        #print(i)
        cv2.imshow("Image window", cv_image)
        cv2.waitKey(1)

image description

So, anybody knows how to get the respective (x,y) position of the detected markers and then use cv2.putText?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Shrijan
close date 2018-11-17 04:08:52.203293

Comments

the interesting part here is: the tvec holds a 3d space position, but to draw it, we would need it's 2d (screen) projection.

maybe we need to look into what drawAxis() does there ?

berak gravatar imageberak ( 2018-11-17 02:44:34 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-11-17 03:01:55 -0600

berak gravatar image

updated 2018-11-17 04:14:25 -0600

it gets slightly advanced here, but to find the 2d position of your marker on the screen, you have to project it from the 3d space of the rvec / tvec back to 2d, in the very same way, drawAxis() does it.

untested (i don't have any aruco markers), but something like this:

# a list with a single point in it (relative to the tvec position):
# maybe you want some x or y offset, so it does not interfere with drawAxis() !
pt = np.array([[-12, -12, 0]], dtype=np.float)
imgpts, _ = cv2.projectPoints(pt, self.rvecs[i], self.tvecs[i], camera_matrix, dist_coeffs)
cv2.putText(cv_image, imgpts[0][0], sometext, ...)
edit flag offensive delete link more

Comments

1

On printing the imgpts i get

('Image points', (array([[[ 363.90325111,  151.41181538]]]), array([[  0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
      5.44941343e+00,  -1.73800790e-02,  -4.86394205e-01,
      8.92040663e-02,   0.00000000e+00,   1.00000000e+00,
      0.00000000e+00,   1.18684255e+00,   2.66874705e-02,
     -1.27499178e+01,   2.27360909e+01,   6.00097359e-04],
   [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
     -1.74236032e-02,   5.47465181e+00,   6.62782315e-01,
      0.00000000e+00,  -1.21241734e-01,   0.00000000e+00,
      1.00000000e+00,  -1.61702849e+00,  -3.63606781e-02,
      3.07593893e+01,  -1.27818469e+01,  -8.17610155e-04]])))

Probably i'll try to find the x,y co-ordinates from the detected corners array

Shrijan gravatar imageShrijan ( 2018-11-17 03:24:23 -0600 )edit

@Shrijan thanks for reporting back !

ok, my bad, got the projectPoints signature wrong (it also returns jacobians)

please see updated answer !

berak gravatar imageberak ( 2018-11-17 03:27:47 -0600 )edit
2

Ahh, it works. Just changed a bit while doing cv2.putText.Have to play with offset only now..Thanks alot.

pt =np.array([[-12, -12, 0]], dtype=np.float)

        #for rvec, tvec in zip(self.rvecs, self.tvecs):
        for i in range(0, self.ids.size):
            #print(self.tvecs[i][0][2])
            cv_image=aruco.drawAxis(cv_image, camera_matrix, camera_distortion, self.rvecs[i], self.tvecs[i], 10)
            #str_position = "trans"%((self.tvecs[i][0]))
            imgpts,_ = cv2.projectPoints(pt, self.rvecs[i], self.tvecs[i], camera_matrix, camera_distortion)
            #print("Image points",imgpts[0][0][1])

            str_position = "MARKER Position x=%4.0f  y=%4.0f  z=%4.0f"%(self.tvecs[i][0][0], self.tvecs[i][0][1], self.tvecs[i][0][2])
            cv2.putText(cv_image, str_position, (int(imgpts[0][0][0]),int(imgpts[0][0][1])), font, 1,
Shrijan gravatar imageShrijan ( 2018-11-17 04:06:32 -0600 )edit

oh, np.array, not a simple list ;)

berak gravatar imageberak ( 2018-11-17 04:13:53 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-11-17 02:42:38 -0600

Seen: 663 times

Last updated: Nov 17 '18