2017-10-18 759 views
0

我正在研究一個機器人項目,就是我需要檢測關鍵點獲取這些點的座標並將它們傳送給機器人進行操作。 我做了相機校準,並使用校準信息從我的相機取消失真圖像,然後應用ORB技術檢測關鍵點。直到現在一切都很好,但我不知道如何映射這些關鍵點座標來與機器人一起工作。如何將像素座標轉換爲世界座標?

這裏是我使用的代碼:

int main(int argc, char** argv) 
{ 

std::vector<KeyPoint> kp; 
Mat frame; 
Mat frame_un; 
Mat camera_matrix =(Mat_<double>(3,3) << 7.4191833420713715e+02, 0.0, 320.0, 0.0, 7.4191833420713715e+02, 240.0, 0.0, 0.0, 
    1.0); 
Mat distortion_coefficients =(Mat_<double>(5,1) << -1.5271566741564191e-01, 1.5488166759164064e+00, 0.0, 0.0, 
    -7.6517765981508861e+00); 

VideoCapture cap(1); // open the default camera 
if (!cap.isOpened()) // check if we succeeded 
    return -1; 

for (;;) 
{ 

    cap.read(frame); // get a new frame from camera 
    if (frame.empty()) 
continue; 
undistort(frame, frame_un, camera_matrix, distortion_coefficients); 
// Default parameters of ORB 
    int nfeatures=30; 
    float scaleFactor=1.2f; 
    int nlevels=8; 
    int edgeThreshold=31; // Changed default (31); 
    int firstLevel=0; 
    int WTA_K=2; 
    int scoreType=ORB::HARRIS_SCORE; 
    int patchSize=31; 
    int fastThreshold=20; 

Ptr<ORB> detector = ORB::create(
    nfeatures, 
    scaleFactor, 
    nlevels, 
    edgeThreshold, 
    firstLevel, 
    WTA_K, 
    scoreType, 
    patchSize, 
    fastThreshold); 

    detector->detect(frame_un, kp); 
    std::cout << "Found " << kp.size() << " Keypoints " << std::endl; 
for(int i=0; i<=kp.size();i++) 
{ 
int x = kp[i].pt.x; 
int y = kp[i].pt.y; 
cout << "Point "<<i<<" Xpos = " << x << " Point "<<i<< " Ypos = " << y << "\n"; 

}  
Mat out; 

    //drawKeypoints(img, kp, out, Scalar::all(255)); 
drawKeypoints(frame_un, kp, out, Scalar::all (255)); 
namedWindow("Kpts", WINDOW_FREERATIO); 
    imshow("Kpts", out); 
waitKey(0); 
destroyWindow("Kpts"); 
} 
    // waitKey(0); 
    return 0; 
} 
+0

有很多方法可以用這種方式使用關鍵點。你對odometry還是其他什麼感興趣?我猜廣義術語是單應性。 – jdv

+0

所以如果我使用單應性技術,可以將這個座標映射到真正的座標,由機器人操作 – Ahmad

+0

當然。這裏有一些討論:https://stackoverflow.com/q/30502687/1531971(和其他人)這個問題感覺它可能有點寬泛,需要更多的研究。 – jdv

回答

0

的座標系與機器人的基地就在地圖的座標系,並使其原點。在做這件事之前,請確保您已經以毫米級精度正確校準了您的視力。

相關問題