也许有人知道什么会导致这个问题。 我有一个简单的代码,用于在一幅全景图像中拼接12幅图像,但却遇到了奇怪的行为。 这是我的MacBook Pro上的拼接结果:
https://drive.google.com/open?id=1f_7i_rb8pnbHEBxlowzFa13MAHvxN07u
我桌面Mac上的拼接结果:
https://drive.google.com/open?id=19CoyPzz6QgDjqG1lUZbphGPYvCAg41hi
我使用的代码是相同,图像也一样。在我的桌面上,我可以毫无问题地构建和运行它,但在我的MacBook上它根本不起作用,它向我显示下一个错误:
OpenCV Error: Assertion failed (imgs.size() == imgs_.size())
in composePanorama, file /tmp/opencv-20171031-87373-6u1izq/opencv-3.3.1/modules/stitching/src/stitcher.cpp, line 168
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/opencv-20171031-87373-6u1izq/opencv-3.3.1/modules/stitching/src/stitcher.cpp:168:
error: (-215) imgs.size() == imgs_.size() in function composePanorama
这是我的代码:
#include <stdio.h>
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/stitching.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv ) {
vector<Mat> images_arr;
const string images[] = {
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/1.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/2.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/3.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/4.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/5.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/6.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/7.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/8.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/9.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/10.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/11.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/12.jpeg",
};
const char* outFile = "/Users/george/CLionProjects/OpenCV_Stitch/out.jpeg";
for(auto path : images) {
Mat image = imread(path, IMREAD_REDUCED_COLOR_2 | IMREAD_IGNORE_ORIENTATION);
images_arr.push_back(image);
}
Mat pano;
Stitcher stitcher = Stitcher::createDefault(false);
stitcher.setRegistrationResol(0.8);
stitcher.setSeamEstimationResol(0.1);
stitcher.setCompositingResol(1);
stitcher.setPanoConfidenceThresh(1);
stitcher.setWaveCorrection(true);
stitcher.setWaveCorrectKind(detail::WAVE_CORRECT_HORIZ);
Stitcher::Status status1 = stitcher.estimateTransform(images_arr);
Stitcher::Status status = stitcher.composePanorama(images_arr, pano);
if (status != Stitcher::OK) {
cout << "Can't stitch images, error code = " << int(status) << endl;
return -1;
}
imwrite(outFile, pano);
return 0;
}
我的CmakeLists.txt配置:
cmake_minimum_required(VERSION 3.8)
project(OpenCV_Stitch)
set(CMAKE_CXX_STANDARD 11)
find_package(OpenCV REQUIRED)
set(SOURCE_FILES main.cpp)
add_executable(OpenCV_Stitch ${SOURCE_FILES})
target_link_libraries(OpenCV_Stitch ${OpenCV_LIBS})
甚至无法想象什么会导致图像上出现黑点。有人碰到过这个吗?有时,当我使用不同的图像缝合opencv时返回错误:调整相机参数失败 我怎么能防止这种情况?也许用一些方法来估计相机旋转或类似的东西?
这里是我试图拼接的图像的链接:
https://drive.google.com/open?id=1-DfSf8eaC7bi37-ZhBpaRt8jHVvO_Qwb
谢谢!
答案 0 :(得分:0)
我的代码收到相同的错误消息。当我修改下面的部分时,它运行没有错误。
Mat pano;
Ptr<Stitcher> stitcher = Stitcher::create(Stitcher::PANORAMA, false);
stitcher->setRegistrationResol(0.8);
stitcher->setSeamEstimationResol(0.1);
stitcher->setCompositingResol(1);
stitcher->setPanoConfidenceThresh(1);
stitcher->setWaveCorrection(true);
stitcher->setWaveCorrectKind(detail::WAVE_CORRECT_HORIZ);
Stitcher::Status status = stitcher->stitch(images_arr, pano);