【发布时间】:2017-11-29 12:48:54
【问题描述】:
也许有人知道是什么导致了这个问题。 我有一个简单的代码,用于在一张全景图像中拼接 12 张图像,但遇到了奇怪的行为。 这是在我的 MacBook Pro 上拼接的结果:
https://drive.google.com/open?id=1f_7i_rb8pnbHEBxlowzFa13MAHvxN07u
在我的桌面 Mac 上拼接的结果:
https://drive.google.com/open?id=19CoyPzz6QgDjqG1lUZbphGPYvCAg41hi
我使用的代码是 same 和图像也一样。在我的桌面 Mac 上,我可以毫无问题地构建和运行它,但在我的 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
谢谢!
【问题讨论】:
-
你解决了这个问题吗?
-
不,黑点留在图像上。
-
你用什么打开/看图?我想知道这是否可能是操作系统的一种不良随机行为。您是否使用“预览”应用在 Eclipse 中打开图片?
-
是的,我用 Preview.app 打开它。与我在桌面 Mac 上使用的相同。我使用了许多工具来打开该图像,结果相同。它与我用于预览的应用程序无关,图像本身与工件一样生成。
-
你能稍微改变一下吗?添加以下行:namedWindow("pano", CV_WINDOW_NORMAL); imshow(“全景”,全景);看看图像是否真的有这些黑色斑点?
标签: opencv