Ask Your Question
0

Projection matrix for voxel carving

asked 2016-04-15 12:23:52 -0600

I am trying to perform space carving/voxel carving with projection matrices generated in opencv

My approach consist in:

  1. Camera calibration using chessboard to get the intrinsic matrix K
  2. I use solvePNP to obtain rotation and translation vectors, rodrigues to get the rotation matrix. I asssamble R and T into one matrix which I multiply by intrinsic matrix (K*[R|T])
  3. In opencv I draw a cube on the chessboard using the drawContours function and I use the projectPoints function so the cube rotates and translates together with the chessboard This seems to work- see the attached image 1.image description
  4. Than I perform voxel carving:

    cube of 200x200x200 voxels of size 4 is generated

    foreach voxel I calculate its image reprojection [u,v,1]T= K[R|T][voxel.x,voxel.y,voxel.z,1]T

    I mask all the voxels that are ~ white (background)

After one image processing (one reprojection) I see a piramide - see figure 2.image description

I would expect a cube. I assumed that since projectPoints works the projection matrix is OK but maybe I am wrong or I should modify it some how before I spent days trying to figure it out with no success so if somebody could help me or point a direction that would be great

My intrinsic matrix : [5.4133176190360371e+002, 0., 3.1423029943981362e+002; 0., 5.4314440666700341e+002, 2.4109085795979527e+002; 0., 0., 1.]

First projection matrix: [-130.3838689234658, 543.2310276120221, -282.2779745141828, 4963.465064332162; 378.6239093571447, -7.628680906981948, -457.9480175480329, 4526.52325286986; -0.4457741775970285, 0.006323269925829211, -0.8951231193780763, 22.58023681026416]

generation of projection matrix

            int board_w = 9;
    int board_h = 6;
    int board_n = board_w*board_h;
    vector<Point2f> corners1;
    vector<Point3f> obj;
    Mat rvec, tvec;
    for (int j = 0; j < board_n; j++)
    {
        obj.push_back(Point3f(j / board_w, (j%board_w), 0.0));         
    }
    solvePnP(obj, corners1, intrinsics, distortion, rvec, tvec, false);
    Rodrigues(rvec, dst);
            hconcat(dst, tvec, proj);
    P = intrinsics*proj;

reprojection of the voxel cube (the code is from http://nghiaho.com/?p=2124)

        X2.at<float>(0) = vox.x;
        X2.at<float>(1) = vox.y;
        X2.at<float>(2) = vox.z;
        X2.at<float>(3) = 1.0;

        X = P * X2;

        int x = X.at<float>(0) / X.at<float>(2);
        int y = X.at<float>(1) / X.at<float>(2);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-12-11 03:36:40 -0600

Hi, I'm trying to attempt voxel carving as well and I have the same problem as you described! I have based my code on the same source (https://github.com/subokita/Sandbox/t... and http://nghiaho.com/?p=2124).

After 19 carves, i get something like this: image description

The reprojection should work, since it projects a given 3D coordinate downto 2D space/image, and your projection matrix looks OK but that all depends on the intrinsic and extrinsic properties of your camera. Otherwise the code for the projection should be OK!

I'm not sure, but I suspect the problem could based on the "vector<double> depths"? However I haven't been able to figure out how :( The depths values comes from the scaling factor in the projection, which should be included when creating the visualization of the voxels..

Have you, or anybody, solved this problem or have any ideas?

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-04-15 12:23:52 -0600

Seen: 917 times

Last updated: Apr 15 '16