opencv圖片拼接報錯cv::Stitcher::ERR_NEED_MORE_IMGS (1)




#include "opencv2/imgcodecs.hpp" #include "opencv2/highgui.hpp" #include "opencv2/stitching.hpp" #include <iostream> using namespace std; using namespace cv; bool try_use_gpu = false; bool divide_images = false; Stitcher::Mode mode = Stitcher::PANORAMA; vector<Mat> imgs; string result_name = "result.jpg"; void printUsage(char** argv); int parseCmdArgs(int argc, char** argv); int main(int argc, char* argv[]) { //int retval = parseCmdArgs(argc, argv); //if (retval) return -1; Mat img1 = imread("/hard_disk2/Receive_files/xls/mask-rcnn-test/QT/1.png"); Mat img2 = imread("/hard_disk2/Receive_files/xls/mask-rcnn-test/QT/2.png"); imgs.push_back(img1); imgs.push_back(img2); // imgs.push_back(img1); // imgs.push_back(img2); // imgs.push_back(img1); // imgs.push_back(img2); Mat pano; Ptr<Stitcher> stitcher = Stitcher::create(mode, try_use_gpu); Stitcher::Status status = stitcher->stitch(imgs, pano); if (status != Stitcher::OK) { cout << "Can't stitch images, error code = " << int(status) << endl; return -1; } imwrite(result_name, pano); waitKey(0); cout << "stitching completed successfully\n" << result_name << " saved!"; return 0; }

 代碼如上,參考https://docs.opencv.org/trunk/d8/d19/tutorial_stitcher.html

運行時報錯cv::Stitcher::ERR_NEED_MORE_IMGS (1),后來查找原因,發現是我隨便選取了兩張圖片進行拼接,然而這兩張圖片並沒有重疊的部分,然后修改了兩張圖片之后,運行正常了。所以進行圖片拼接的時候需要注意要有重疊部分才可以。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM