OpenCV ImageStitching App在Visual上工作,不与QTCreator一起工作。代码在两者中都是相同的

时间:2015-09-07 19:37:34

标签: c++ visual-studio opencv visual-studio-2013 qt-creator

我有QTCreator申请。它使用OpenCV 2.4.11。我在Visual上有相同的应用程序。代码在两者中都是相同的。

OpenCV for Microsoft Visual 2013是使用以下链接制作的:

https://www.youtube.com/watch?v=e_TQ9c3n_d8

是2.4.10,但2.4.11也是如此。

我在本教程中配置了QtCreator:

How to link opencv in QtCreator and use Qt library

现在代码:

#include <opencv2\highgui\highgui.hpp>
#include <iostream>
#include <fstream>
#include <opencv2\highgui\highgui.hpp>
#include "opencv2\stitching\stitcher.hpp"
using namespace cv;
using namespace std;
void ReadPhotos();

double begin_t, end_t;
int photo_number = 0;
Mat photos[100];
Mat image;
vector< Mat > ImagesVector;
vector<Mat> roisVector;

int main()
{
cout << "Starting program!" << endl;

ReadPhotos();

Size size(1050, 600);

for (int i = 0; i < photo_number; i++){
    //resize(photos[i], photos[i], size);
    ImagesVector.push_back(photos[i]);
}

Stitcher stitcher = Stitcher::createDefault(true);

stitcher.setWarper(new SphericalWarper());
stitcher.setFeaturesFinder(new detail::SurfFeaturesFinder(300, 3, 4, 3, 4));
stitcher.setRegistrationResol(0.9);
stitcher.setSeamEstimationResol(0.9);
stitcher.setCompositingResol(1);
stitcher.setPanoConfidenceThresh(1);
stitcher.setWaveCorrection(true);
stitcher.setWaveCorrectKind(detail::WAVE_CORRECT_HORIZ);
stitcher.setFeaturesMatcher(new detail::BestOf2NearestMatcher(false, 0.3));
stitcher.setBundleAdjuster(new detail::BundleAdjusterRay());
Stitcher::Status status = Stitcher::ERR_NEED_MORE_IMGS;
try{
    status = stitcher.stitch(ImagesVector, image);
}
catch (cv::Exception e){}

imwrite("panorama.jpg", image);

waitKey(0);
return 0;
}

void ReadPhotos(){

string sourceIN;
string sourcePhoto;

sourceIN = "paths1.txt";
ifstream FileIN(sourceIN);

if (FileIN.is_open())
{
    while (getline(FileIN, sourcePhoto)){

        photos[photo_number] = imread(sourcePhoto, 1);
        photo_number++;
    }
}
else{
    cout << "Can't find file" << endl;
}

cout << "Number of photos: " << photo_number << endl;

}

读取照片功能从txt文件中获取图像的路径并加载照片。

在视觉工作室,它工作得很好,我可以缝合3500x2000的结果图像,它提供了很好的输出全景。在QtCreator中,我尝试缝合相同的图像,并给出以下错误:

  1. OpenCV错误:OutOfMemoryError中的内存不足(无法分配290519044字节),文件C:\ OpenCV2411 \ opencv \ sources \ modules \ core \ src \ alloc.cpp,第52行 在抛出'cv :: Exception'的实例后终止调用 what():C:\ OpenCV2411 \ opencv \ sources \ modules \ core \ src \ alloc.cpp:52:错误:( - 4)无法在函数OutOfMemoryError中分配290519044个字节

  2. 错误的分配 - 抱歉,我无法再次出现此错误,因此无法完全复制。

  3. 任何人都知道为什么相同的代码无法在QTCreator上工作并且在Visual Studio 2013中工作?图书馆是一样的。我能想到的一件事是我用Cmake为QTCreator构建了库。也许它与此有关。

0 个答案:

没有答案