旅行好きなソフトエンジニアの備忘録

プログラミングや技術関連のメモを始めました

【OpenCV】 パノラマ画像を作成する

OpenCVの復習が必要になったのでメモしておきます。

// 画像を読み込む
UMat source1;
imread("scene1.jpg", CV_LOAD_IMAGE_COLOR).copyTo(source1);
if (source1.empty())
{
    throw runtime_error("Failed to open image");
}
UMat source2;
imread("scene2.jpg", CV_LOAD_IMAGE_COLOR).copyTo(source2);
if (source2.empty())
{
    throw runtime_error("Failed to open image");
}
vector<UMat> sources;
sources.push_back(source1);
sources.push_back(source2);

// パノラマ画像を作成する
Stitcher stitcher = Stitcher::createDefault();
UMat destination;
Stitcher::Status status = stitcher.stitch(sources, destination);
if (status != Stitcher::OK)
{
    throw runtime_error("Failed to stitch images");
}

imshow("source1", source1);
imshow("source2", source2);
imshow("destination", destination);

f:id:ni4muraano:20170117183340j:plain f:id:ni4muraano:20170117183353j:plain f:id:ni4muraano:20170117183405j:plain

さらに進化した画像処理ライブラリの定番 OpenCV 3基本プログラミング

さらに進化した画像処理ライブラリの定番 OpenCV 3基本プログラミング