opencv:使用cout与Mat对象抛出异常



我需要打印Mat对象,程序抛出异常…该项目非常简单:创建Mat对象并使用cout打印-就像在OpenCV教程中一样:

#include <core/core.hpp>
#include <highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char *argv[])
{
    Mat O = Mat::ones(2, 2, CV_32F);
    cout << "O = " << endl << " " << O << endl << endl;
    // Point2f P(5, 1);
    // cout << "Point (2D) = " << P << endl << endl;
return 0;
}

异常显示:Unhandled exception at 0x59430671 (msvcp100d.dll) in printingTest.exe: 0xC0000005: Access violation reading location 0x00000000。控制台只显示

O = [

准确地说,它停在"operations.hpp"处:

static inline std::ostream& operator << (std::ostream& out, const Mat& mtx) { Formatter::get()->write(out, mtx); return out; }

它似乎是空的,但有人知道为什么吗?教程说它应该可以工作…

我以前有过类似的抛出异常的问题,我在这里解决了:

http://answers.opencv.org/question/5113/problem-with-reading-image-to-mat/

是否可能存在另一个环境变量冲突?还是因为我用的是VS2012,而OpenCV只适用于v10?

注释后的Point2f正常工作

您的代码在VS2010中工作得很好。确保您链接了正确的库(发布与调试)。如果这没有帮助,请尝试重新安装openCV或在VS2012上自己构建,使用cmake从源代码准备它。

最新更新