环境:Windows 7 x64,Visual Studio 2013,openCV 2.4.9
我是openCV和C ++的新手。刚刚配置了opencv的环境,然后我从Internet复制了一些程序进行测试,结果,其中一个程序正确但有些报告错误。
1.第一个问题:
我只能发布2个链接,所以我将两个图像合二为一。
上面的程序运行正常并且一次得到错误,我们可以看到“imread()”返回空矩阵。我知道它报告错误:“imshow()”通过调试。
如果我更改下码:将“imread”替换为“cvLoadImage”,它可以显示图像,但窗口的标签仍然是无法识别的中文代码。
#include "stdafx.h"
#include<iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main()
{
IplImage* img = cvLoadImage("G:\\demo.png");
cvNamedWindow("图像显示窗口");
cvShowImage("图像显示窗口", img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("图像显示窗口");
return 0;
waitKey(6000);
}
#include "stdafx.h"
#include<iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main()
{
// 读入一张图片(游戏原画)
Mat img = imread("G:\\demo.png");
// 创建一个名为 "游戏原画"窗口
namedWindow("游戏原画");
// 在窗口中显示游戏原画
imshow("游戏原画", img);
// 等待6000 ms后窗口自动关闭
waitKey(6000);
}
我用cvLoadImage()替换imread(),在监视img有数据,并且我自己添加了行“stitcher.estimateTransform()”,然后在这一行报告下一行相同的错误:“stitcher .stitch()”。
我认为cvLoadImage是否不能与Mat类型或Stitcher一起使用,但imread将返回空矩阵。
#include "stdafx.h"
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/stitching/stitcher.hpp"
using namespace std;
using namespace cv;
bool try_use_gpu = false;
vector<Mat> imgs;
string result_name = "result.jpg";
//void printUsage();
//int parseCmdArgs(int argc, char** argv);
int main(int argc, char* argv[])
{
Mat img = cvLoadImage("12.JPG");
imgs.push_back(img);
img = cvLoadImage("22.JPG");
imgs.push_back(img);
Mat pano;
Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
Stitcher::Status status = stitcher.estimateTransform(imgs);
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);
return 0;
}
代码或配置是否有问题?我在网上搜索了很长时间。但没用。请帮助或尝试提供一些如何实现这一点的想法。谢谢你的帮助。