22

ホモグラフィを計算し、透視変換を取り出しました。1つのウィンドウに2つの画像を2つ表示できますが、それらをマージすることはできません.ここに私の画像例があります-> 画像1

画像2

私が使用しているコード thiscode ->

cv::warpPerspective(image2,warpresult2,homography,cv::Size(2*image2.cols,image2.rows));


Mat imgResult(image1.rows,2*image1.cols,image1.type());

Mat roiImgResult_Left = imgResult(Rect(0,0,image1.cols,image1.rows)); 
Mat roiImgResult_Right = imgResult(Rect(image1.cols,0,image2.cols,image2.rows)); 

Mat roiImg1 = image1(Rect(0,0,image1.cols,image1.rows));
Mat roiImg2 = warpresult2(Rect(0,0,image2.cols,image2.rows));

roiImg1.copyTo(roiImgResult_Left); //Img1 will be on the left of imgResult
roiImg2.copyTo(roiImgResult_Right); //Img2 will be on the right of imgResult

imshow("Finalimg",imgResult);
imwrite("C:\\OpenCv_Projects\\outputimage.jpg",imgResult);
cvWaitKey(0);

問題は、roiImgResult_right に与えている座標にあると思います。

出力画像は -> 出力画像 ご覧のとおり、画像が正しく結合されておらず、右側に黒い領域があります。それを削除するにはどうすればよいですか?

4

4 に答える 4

17

OpenCV にはすでにイメージ スティッチングが実装されています。「-D BUILD_EXAMPLES」でコンパイルすると、バイナリのstitching_detailedを使用できます。使い方は簡単です:./stitching_detailed img1 img2 ...

または、stitcher クラスを使用することもできます (例はhereから):

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/stitching/stitcher.hpp"

using namespace std;
using namespace cv;

bool try_use_gpu = false;
string result_name = "result.jpg";

int main(int argc, char* argv[])
{
    vector<Mat> imgs;
    // add images...

    Mat pano;
    Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
    stitcher.stitch(imgs, pano);
    imwrite(result_name, pano);
}
于 2012-04-21T06:53:34.450 に答える
7
  • 画像ブレンディング:ラプラシアン ピラミッドブレンディングを使用できます。opencvを使用したサンプル コードを参照してください。好きなマスク (バイナリ マスク) を使用できます。

  • create Panorama パノラマを作成したい場合は、Min-Cut Stitching を使用できます。パノラマ処理を行うこのコードを見つけました。

于 2012-04-21T08:21:15.570 に答える
1

関数を使用して、2 つの画像を簡単にブレンドできaddWeighted()ます。ただし、同じサイズの画像を作成する必要があります。

画像のサイズが異なる場合は、まず 2 つの画像のサイズを変更します。次に、次の関数を呼び出します。

addWeighted(src1, alpha, src2, beta, 0.0, dst);

Mat2 つのファイルを宣言する

src1 = imread("c://test//blend1.jpg");
src2 = imread("c://test//blend2.jpg");

また、宣言alphabetaて結果を に保存しMat dstます。

ここで詳細を取得することもできますOpencvを使用した画像のブレンド

于 2016-06-25T08:15:52.343 に答える