Ask Your Question
0

Marker pose calculation with solvepnp

asked 2017-11-12 17:13:49 -0600

MaxWell gravatar image

Hi,

I'm trying to get my rectangular marker pose via the solvepnp() function. It just needs to detect the marker pose, it doesn't need to place an object on top of it. Opencv gives the next information about this function:

bool cv::solvePnP   (
        InputArray      objectPoints,
        InputArray      imagePoints,
        InputArray      cameraMatrix,
        InputArray      distCoeffs,
        OutputArray     rvec,
        OutputArray     tvec,
        bool            useExtrinsicGuess = false,
        int             flags = SOLVEPNP_ITERATIVE)

I believe that the imagePoints array are the corners of my rectangular marker. And the cameraMatrix and distCoeffs have something to do with the camera parameters? I have already calibrated my camera with the openCV sample program, so I have a parameter xml file, can I do something with this? The rvec and tvec are offcours the rotation and translation vectors and via Rodrigez() I can get the pose of the marker. But for the objectPoints array, I have no idee. and don't know what I have to do with it.

Can someone help me with this?

Thanks!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-11-12 19:31:13 -0600

Tetragramm gravatar image

imagePts is the 2d points of the marker that you find in the image.

objectPts is the 3d points that directly correspond to the 2d points.

For example, a 8x8 chessboard might have (0,0,0)...(8,0,0)(0,1,0)...(8,8,0) as the objectPts

See the tutorial HERE

edit flag offensive delete link more

Comments

(8,8,0): I've never seen an 8m calibration target :)

FooBar gravatar imageFooBar ( 2017-11-13 01:36:33 -0600 )edit

Maybe he's trying to calibrate an orbital satellite? ;)

For the record, the object points are measured in units like your coordinate system. For cameraCalibration, it doesn't matter the scale, so you can just use random ones. In this case, you should carefully measure the size of the square in real life with a ruler or meter stick and use that as the value.

Or, if you're not using a chessboard, you just have to know the 3d shape of the object you are using as your marker. Since you call it rectangular, it'll still be flat. Just pick one corner or the center of it as (0,0,0), and measure out the locations to all the other points of interest (corners, intersections, ect)

Tetragramm gravatar imageTetragramm ( 2017-11-13 05:16:03 -0600 )edit

So if I'm correct for the objectPoints I have to create an array of the different points of interests. And for example if my marker is a black rectangle with a white triangle in it, I have to measure all the corners of the rectangle and triangle which are the points of interest?

For the camera matrix can i use the following values, I got those from calibrating my camera with the calibration sample.

<camera_matrix type_id="opencv-matrix">
   <rows>3</rows>
   <cols>3</cols>
   <dt>d</dt>
   <data>
      5.0467113933335992e+02 0. 320. 0. 5.0467113933335992e+02 240. 0. 0. 1.
   </data>
</camera_matrix>
MaxWell gravatar imageMaxWell ( 2017-11-13 06:17:38 -0600 )edit

That's correct. It is important to remember that the array of object points you pass into solvePnP has to match 1-1 with the detected points. Whether you do that by finding all the points, or by filtering out those not found, it requires some intelligence on the part of the program.

Tetragramm gravatar imageTetragramm ( 2017-11-13 18:21:24 -0600 )edit

@Tetragramm you're been really helpfully! But one last question, does the order of the points need to be same always? For example does the top of the triangle always need to be the first point or can I change the order (random)?

MaxWell gravatar imageMaxWell ( 2017-11-15 01:52:38 -0600 )edit

You can change the order at will, but the order must be the same between the two lists.

IE, if object point 5 is the TL corner, then the image point 5 must be the TL corner.

Tetragramm gravatar imageTetragramm ( 2017-11-15 17:55:08 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-11-12 17:13:49 -0600

Seen: 3,274 times

Last updated: Nov 12 '17