wg-perception / linemod

An OR pipeline based on LINE-MOD from OpenCV
47 stars 54 forks source link

Point coordinates of detected object #32

Closed xMutzelx closed 8 years ago

xMutzelx commented 8 years ago

Hi community, after Linemod detected an object, I would like to read the exact coordinates of the detected object. Something like: P1(220/230) P2(221/230) ... I have found code that returns the bounding box of the detected object, but there are to many points that doesn't belong to the object. I tried to calculate the points with the R-matrix and T-matrix but I don't get it right. Can someone please explain me how I can calculate/get every point coordinate? Sorry if this is a stupid question, but I think those coordinates would be nice for everybody who tries to modify/improve LineMod. Thank you very much, I really appreciate it.

My output of every variable:

depth_real_model_raw: 67 40
depth_real_ref_raw: 640 480
Match: 87 257
Rect_ref: 87 257
Rect_model: 87 257 67 40
T: [-0.280007, 0.0317065, 0.189323]
 R: [0.16856061, -0.23157644, -0.95810217;
  -0.89435035, -0.44457686, -0.049888521;
  -0.41439685, 0.86528826, -0.28204873]
T: [-0.280007, 0.0317065, 0.189323]
 R: [0.16856061, -0.23157644, -0.95810217;
  -0.89435035, -0.44457686, -0.049888521;
  -0.41439685, 0.86528826, -0.28204873]
pts_real_ref_temp: 0 [-0.227042, 0.00267829, 0.546]
pts_real_model_temp: 0 [0.100638, -0.00946573, -0.257265]
pts_real_ref_temp: 1 [-0.225593, 0.00267338, 0.545]
pts_real_model_temp: 1 [0.100638, -0.00946573, -0.257265]
pts_real_ref_temp: 2 [-0.22456, 0.00267338, 0.545]
pts_real_model_temp: 2 [0.100638, -0.00946573, -0.257265]
pts_model.size: 2551
pts_model.1: [0.106741, -0.00810874, -0.264011]
pts_ref.1: [-0.225593, 0.00267338, 0.545]
it_o2-t: [-0.196518, 0.0211954, 0.554]
T: [-0.196662, 0.0221105, 0.553999]
 R: [0.2549791, -0.31554195, -0.91401243;
  -0.72558904, -0.68724585, 0.034840584;
  -0.6391449, 0.65431392, -0.40418717]
43af9b1708c74566067abf1a4801e645 94.0476 icp 0.260918,  ratio 0 or 0
matches  3 / 1 / 3
xMutzelx commented 8 years ago

I got it! Here is my Code in linemod_detect.cpp in line 382:

/* Check every pixel of the image. CARE: rows cols world */
for(int i=0; i<depth_real_model_raw.cols; i++)
 {
    for(int j=0; j<depth_real_model_raw.rows;j++)
     {
        cv::Vec3f & pixel = depth_real_model_raw.at<cv::Vec3f>(j,i); 

                if(pixel[0]!=pixel[0] || pixel[1]!=pixel[1] || pixel[2]!=pixel[2])
                        std::cout<<"Pixel is not a number (NAN)"<<std::endl;

        else if(pixel[2]<0.1||pixel[2]>1.0)
            std::cout<<"Z-value is invalid"<<std::endl;

        else
             std::cout<<"This pixel contains valid data"<<std::endl;
    }
  }
std::cout<<"Match: "<<match.x<<" "<<match.y<<std::endl;

This x and y coordinates are inside the bounding box so you also have to translate them. Variable "match" contains the relevant informations (match.x and match.y). There are still some problems with this solution. If the model doesn't fit the real world object perfectly some informations are lost. For me it is enough information, but if there is a better solution please let me know.

vrabaud commented 8 years ago

@nlyubova , any opinion on that?