0

関数は2つの画像をつなぎ合わせます...うまくいきます...

関数:

for( int i = 1; i<(4); i++ )
{
test=Bildpaar(test,image1[2+z]);
z=z+1;
}
imwrite("../superrechts.jpg",test);

しかし、パノラマ画像の黒い部分があり、3 番目の画像しか見えないため、2 回目の反復は失敗します...

私の機能

Mat Bildpaar(Mat Bild1,Mat Bild2)

{


Mat img_keypoints_1;
std::vector<KeyPoint> keypoints_1,keypoints_2;//anzahl der keypoint vektoren


int minHessian = 50;


  FastFeatureDetector  detector( minHessian); 

  detector.detect( Bild1, keypoints_1 );
  detector.detect( Bild2, keypoints_2 );

  //-- Draw keypoints

  drawKeypoints( Bild1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );



 //%%%%%%%%%%%%%%%%%%%%%%%%&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
 //Discriptor
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 SiftDescriptorExtractor extractor; //Zeit
 Mat descriptors_1,descriptors_2;

extractor.compute( Bild1, keypoints_1, descriptors_1 );
extractor.compute( Bild2, keypoints_2, descriptors_2 );

//  waitKey(0);
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//Matcher
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//-- Step 3: Matching descriptor vectors using FLANN matcher

std::vector< DMatch > matches;

 FlannBasedMatcher matcher;
 matcher.match( descriptors_1, descriptors_2, matches );

double max_dist = 0; double min_dist = 100;



Mat img_matches;
drawMatches(Bild1, keypoints_1, Bild2, keypoints_2, matches, img_matches);
//namedWindow( filename, CV_WINDOW_NORMAL );// Create a window for display.  
//imshow(filename, img_matches[i]);



std::vector< DMatch > good_matches;



 for( int i = 0; i < descriptors_1.rows; i++ )
  { double dist = matches[i].distance;
    if( dist < min_dist ) min_dist = dist;
    if( dist > max_dist ) max_dist = dist;
  }



  for( int i = 0; i < descriptors_1.rows; i++ )
  { if( matches[i].distance < 2*min_dist )
    { good_matches.push_back( matches[i]); 
  }

  }

  Mat img_matches1;

  drawMatches( Bild1, keypoints_1, Bild2, keypoints_2,
               good_matches, img_matches1, Scalar::all(-1), Scalar::all(-1),
               vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );

  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  //bis hierhin geht es
  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 std::vector< Point2f > obj1;
 std::vector< Point2f > scene1;


for( int i = 0; i < good_matches.size(); i++ )
 {
 //-- Get the keypoints from the good matches
 obj1.push_back( keypoints_1[ good_matches[i].queryIdx ].pt );
 scene1.push_back( keypoints_2[ good_matches[i].trainIdx ].pt );
 }

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // Find the Homography Matrix
  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
Mat H;


 H= findHomography( scene1, obj1, CV_RANSAC,5 );

 std::vector<Point2f> obj_corners(4);
 obj_corners[0] = cvPoint(0,0); obj_corners[1] = cvPoint( Bild1.cols, 0 );
 obj_corners[2] = cvPoint( Bild1.cols, Bild1.rows ); obj_corners[3] = cvPoint( 0, Bild1.rows );
  std::vector<Point2f> scene_corners(4);

  perspectiveTransform( obj_corners, scene_corners, H);
  //-- Show detected matches
  //-- Draw lines between the corners (the mapped object in the scene - image_2 )
  line( img_matches1, scene_corners[0] + Point2f( Bild1.cols, 0), scene_corners[1] + Point2f( Bild1.cols, 0), Scalar(0, 255, 0), 4 );
  line( img_matches1, scene_corners[1] + Point2f( Bild1.cols, 0), scene_corners[2] + Point2f( Bild1.cols, 0), Scalar( 0, 255, 0), 4 );
  line( img_matches1, scene_corners[2] + Point2f( Bild1.cols, 0), scene_corners[3] + Point2f( Bild1.cols, 0), Scalar( 0, 255, 0), 4 );
  line( img_matches1, scene_corners[3] + Point2f( Bild1.cols, 0), scene_corners[0] + Point2f( Bild1.cols, 0), Scalar( 0, 255, 0), 4 );
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//Warp images
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Mat result;

warpPerspective(Bild2, result, H, Size(Bild2.cols*2, Bild2.rows), INTER_CUBIC);
Mat final(Size(Bild2.cols + Bild1.cols, Bild2.rows),CV_8UC3);//richtig //testen ob Spaltenanzahl auswirkungen auf das ergebnis hat



//velikost img1
Mat roi1(final, Rect(0, 0,  Bild1.cols, Bild1.rows));

Mat roi2(final, Rect(0, 0,  result.cols, result.rows));
result.copyTo(roi2);
Bild1.copyTo(roi1);



return final;


}

私の見解では、私はロイでいくつかの間違いを犯しています...

ブレンドを試してみましたが、同じサイズの画像でしか機能しません...または黒い部分を削除できます...私にできる最善のことは何ですか? たぶん、あるロイを別のロイにコピーして、順序を変更しようとします

result.copyTo(roi2);
Bild1.copyTo(roi1);

ある場合には左の写真が見え、別の場合には右の写真が見えました...どうすれば両方を一緒に見ることができますか?

よろしくお願いします

私は1つの方法を見つけました(しかし、それは良い方法ではありません)。

まず、2つの画像をステッチします(final1と呼ばれます)。次に、final1と画像3をステッチするときに、ロワをブレンドする必要があります...そして、アルファで遊ぶ必要があります...

Mat blendo;
double alpha=0.3;
double beta = ( 1.0 - alpha );
addWeighted( roi1, alpha, roi2, beta, 0.0, blendo);
4

0 に答える 0