fitting a 3D model to the target point cloud by ceres solver optimization

478 views
Skip to first unread message

t1436...@gmail.com

unread,
Jul 10, 2017, 11:13:55 AM7/10/17
to Ceres Solver

Hi,

Background:    
    I am using ceres solver to fit a 3D model to the target point cloud, that is, optimize each vertex position of the model to make the model
and target point cloud achieve the maximun similarity. So i use the point term to measure the similarity of model vertex and target point
cloud in my objective function. The target point cloud is represented by corresponding depth image acquired by the camera .


Definition:
The point term is the sum of ||vi -g(u)||,(i=1,2.....n) . 

vi     : (x_i  ,y_i,z_i )---model vertex position

g(u): which maps 2D points  u to 3D world points using camera  information.
           depth image—width : w,  height :h  ,camera  focal length :f

u:( p,q )  - 2D depth image coordinate( the image location of  the closet point to vi)


The point term consists of three residual terms : ||xi-gx|| ,||yi-gy|| ,||zi - gz||

gx,gy and gz are the x,y,z components of g(u) .


Code:

The depth value could not be expressed by a explicit formula ,so i want to calculate the Jacobian martix by analytic method.But i am confused about this.

I set 3 residuals,2 parameter blocks

parameter block1: xyz

parameter block2:pq

class PointFunctor:public ceres::SizedCostFunction<3,3,2>{//xyz,pq
public:
   
virtual ~PointFunctor(){}

   
virtual bool Evaluate(const double * const *parameters, double *residuals, double **jacobians) const{

       
//camera parameters
       
int depth_image_width = 320;
       
int depth_image_height = 240;
       
double focal_len = 578.5;

       
//3D model vertex position
       
double x_model = parameters[0][0];
       
double y_model = parameters[0][1];
       
double z_model = parameters[0][2];

       
//u position in the depth imag
       
double p = parameters[0][3];
       
double q = parameters[0][4];
 
       
double depth_value = bilinearInterpolation(p,q);//the depth value need to be interpolated
       
//map 2D depth point u(p,q) to 3D world points using camera parameters.
       
double x_depth = (p - depth_image_width/2) * depth_value / focal_len;
       
double y_depth = (depth_image_height/2 -q) * depth_value / focal_len;
       
double z_depth = depth_value;


        residuals
[0] = x_model - x_depth;
        residuals
[1] = y_model - y_depth;
        residuals
[2] = z_model - z_depth;

           //which form should i adopt.?? or other form?

           //1.
                         
if( !jacobians ){
           
return true;
       
}
       
double *jacobian = jacobians[0];//??
       
if( !jacobian ){
           
return true;
       
}

        jacobian
[0]= function expression;
        jacobian
[1]= function expression;
        jacobian
[2]= function expression;
        jacobian
[3]= function expression;
        jacobian
[4]= function expression;

    //2.?
       jacobians[0][0] = function expression;
         jacobians
[0][1] =
function expression;
         jacobians
[0][2] =
function expression;
         jacobians
[0][3] =
function expression;
         jacobians
[0][4] =
function expression;

        jacobians[1][0] =
function expression;
        jacobians[1][1] =
function expression;
         jacobians[1][2] =
function expression;
       jacobians[1][3] =
function expression;
        jacobians[1][4] =
function expression;

       jacobians[2][0] =
function expression;
       jacobians[2][1] =
function expression;
        jacobians[2][2] =
function expression;
        jacobians[2][3] =
function expression;
        jacobians[2][4] =
function expression;



       
return true;
   
}
};
So i want to know the form of Jacobian ,i have 3 residuals, 5 unknow parameters(x,y,z,p,q)

Should  i code like this? 

//i=0,1,2,3,4
jacobians[0][i] =some expression;

jacobians[1][i]=some expression;
jacobians[2][i]
=some expression;


or this?

jacobians[0] =some expression;
jacobians[1]=some expression;
jacobians[2]
=some expression;
jacobians[3] =some expression;
jacobians[4] =some expression;


or else?



Thanks,

walden


Sameer Agarwal

unread,
Jul 11, 2017, 2:00:06 AM7/11/17
to Ceres Solver
walden,
it depends on how your parameter blocks are laid out.
do x_model, y_model, z_model and p and q form a parameter block with 5 parameters?
Sameer


--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/7c47d5ce-faec-49b5-b128-64d2df2907b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

t1436...@gmail.com

unread,
Jul 11, 2017, 3:02:59 AM7/11/17
to Ceres Solver
Thanks , Sammer.
In my code, i set 3 residuals, 2 parameter blocks, 5 parameters in total.
parameter block 1 consists of :  x_model,y_model,z_model
parameter block 2 consists of: q  ,  q 

在 2017年7月11日星期二 UTC+8下午2:00:06,Sameer Agarwal写道:

Sameer Agarwal

unread,
Jul 11, 2017, 9:23:25 AM7/11/17
to Ceres Solver
then the way you access the parameters is (assuming the model parameters are first)

model_x = parameters[0][0];
model_y = parameters[0][1];
model_z = parameters[0][2];

p = parameters[1][0];
q = parameters[1][1];

and correspondingly the jacobian w.r.t the model positions gets assigned to jacobians[0] and w.r.t p and q to jacobians[1].

Sameer


t1436...@gmail.com

unread,
Jul 18, 2017, 12:51:06 AM7/18/17
to Ceres Solver
Thank you,Sameer. Sorry for my late reply. I was out last week. And I will try again according to your advice.

在 2017年7月11日星期二 UTC+8下午9:23:25,Sameer Agarwal写道:
Reply all
Reply to author
Forward
0 new messages