2014-02-25 53 views
0

嗨我想縫合一些圖像,而不使用opencv提供的針類。但是,輸出是意想不到的。 我會用輸入和輸出圖像來解釋它。與opencv手動縫合

輸入1 enter image description here

輸入2 enter image description here

預期輸出enter image description here

實際產出enter image description here

我覺得有什麼不對我的投資回報率的複製。任何人請幫助!

我的拼接部分代碼如下 -

std::vector<Point2f> points1,points2; 
     for(int i = 0; i < matches1.size(); i++) 
      { 
      points1.push_back(keypoints_input1[matches1[i].queryIdx ].pt); 
      points2.push_back(keypoints_input2[matches1[i].trainIdx ].pt); 
      } 
     /* Find the Homography Matrix for current and next frame*/ 
     Mat H1 = findHomography(points2, points1, CV_RANSAC); 
     /* Use the Homography Matrix to warp the images*/ 
     cv::Mat result1; 
     warpPerspective(input2, result1, H1, Size(input2.cols+150, input2.rows+150),  INTER_CUBIC); 
     Mat stitch_1(Size(input2.cols+150, input2.rows+150),CV_8UC3); 
     Mat roi1(stitch_1, Rect(0, 0, input1.cols, input1.rows)); 
     Mat roi2(stitch_1, Rect(0, 0, result1.cols, result1.rows)); 


     input2.copyTo(roi1); 
    result1.copyTo(roi2); 

誰能告訴我在哪裏,我錯了?謝謝。

編輯:輸入1(640,360)和輸入2(790,510)大小不同。

回答

0

我希望this example可以幫到你。

這是有趣的測試不同的圖像。

編輯:

試試這個代碼:

Mat stitch_1(Size(input2.cols*2+ input1.rows,input2.rows*2),CV_8UC3); 
Mat roi1(stitch_1, Rect(0, 0, input1.cols, input1.rows)); 
Mat roi2(stitch_1, Rect(0, 0, result1.cols, result1.rows)); 
result1.copyTo(roi2); 
input1.copyTo(roi1); 
imshow("final", stitch_1); 
+0

謝謝您的回答,但在鏈接輸入圖像的尺寸相同的。我也試過這個代碼,但它不起作用。 – MMH

+0

我編輯了我的答案,希望工程 – dervish

+0

抱歉,但它有類似的輸出,有一個黑色區域較大。謝謝 – MMH