Ask Your Question
0

how to use ICP in openCV

asked 2018-06-06 08:57:13 -0600

w33z gravatar image

Hi,

I want to write a small programm to understand how the ICP work and want to test it. But i don't understand the function call of the ICP function, see code...

https://docs.opencv.org/3.1.0/dc/d9b/...

Can somebody show me how to do the ICP with 2 MATs? Or Any Idea/tip?

#include <iostream>
#include <opencv2/opencv.hpp>
#include <string>
#include <icp.hpp>
#include <ppf_match_3d.hpp>
#include <ppf_helpers.hpp>



using namespace std;
using namespace cv;
using namespace ppf_match_3d;

int main() {

Mat outputPLY;

// load PLYs
Mat iFirst     = loadPLYSimple("1.ply");
Mat iSecond = loadPLYSimple("2.ply");

ICP icp;


if((iFirst.type()==CV_32F)&&(iSecond.type()==CV_32F))
{
    // i dont understand this function with its parameters
    // is this the ICP ? 
    int t = icp.registerModelToScene(iFirst, iSecond, ?...?);

    // save solution of ICP as new PLY
    if(t)
    {
            //writePLY(outputPLY,"/home/sys/solution.ply");
    }
}

    return 0;
}
edit retag flag offensive close merge delete

Comments

please use current docs , not outdated 3.1.0

berak gravatar imageberak ( 2018-06-06 23:31:44 -0600 )edit

2 answers

Sort by » oldest newest most voted
2

answered 2018-06-13 06:03:56 -0600

w33z gravatar image

updated 2018-06-14 07:15:50 -0600

I calculated the normals with:

Mat pcNormals;
Vec3d viewpoint_1(0, 0, 0);
computeNormalsPC3d(pc, pcNormals, 6, false, viewpoint_1);

Now the PLYs look like:

ply
format ascii 1.0
element vertex 38304
property float x
property float y
property float z
property float nx
property float ny
property float nz
end_header
0.000681958 -0.00157701 0.00381835 0.985197 0.0119866 -0.171006
....

And I tried the sample that you have refer. But I don't unerstand the outputs... I have PointClouds of an object with different views. for example one cloud shows the object from the front and the next pointcloud from 10° different angle an so on (every pointcloud sees only one side of the object). After all i want a 3D pointcloud of the whole object from the single point clouds.
Now I add two pointclouds to the sample, than I use the result and add another pointcloud to the sample. The output is the first input as single points instead a constant surface

sorry for the amateur questions - opencv is new for me.

left - right input 1 - input 2 - output image description

In my opinion, the dinosaur from the second image has to fit in to the scene, but this don't happen

edit flag offensive delete link more
1

answered 2018-06-06 23:51:10 -0600

berak gravatar image

updated 2018-06-07 01:55:14 -0600

i've never used it, but from the docs it should be like:

Matx44d pose; // transformation from model to scene
double error;
icp.registerModelToScene(iFirst, iSecond, error, pose);

// now you can transform the model into the scene:
Mat output = ppf_match_3d::transformPCPose(iFirst, pose);

note, that it expects (at least) the scene model to have proper normals, the PLY header should look like:

ply
...
property float x
property float y
property float z
property float nx
property float ny
property float nz
...
end_header

also have a look at the sample here

edit flag offensive delete link more

Comments

thanks for your answer, it helped a lot.

ah ok, when I am right, I need the normals for the ICP algorithm, at the moment i have only the x,y,z data in my PLYs, so I need the normals too.

w33z gravatar imagew33z ( 2018-06-08 01:13:14 -0600 )edit

yes, the scene needs normals. if you have face information, then it's easy to generate(face) normals (cross-product of the triange edges)

in the meantime, you can try the ply files from the samples folder

berak gravatar imageberak ( 2018-06-08 01:36:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-06-06 08:57:13 -0600

Seen: 5,023 times

Last updated: Jun 14 '18