【发布时间】:2013-01-17 07:50:38
【问题描述】:
我需要打印我的 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; }
看起来“out”是空的,但有人知道为什么吗?教程说它应该可以工作......
我之前遇到过类似的抛出异常的问题,我在这里解决了:
http://answers.opencv.org/question/5113/problem-with-reading-image-to-mat/
是否有可能是另一个环境变量冲突?或者可能是碰撞,因为我使用的是 VS2012,而 OpenCV 仅适用于 v10?
被注释的Point2f的东西正常工作。
【问题讨论】:
-
您使用的是用 VS10 构建的 OpenCV。 DLL 中的
ostream operator <<正在使用来自VC 10 Runtime 的运算符。当您从 VC 11 运行时调用ostream operator <<时。 DLL 存在冲突。 -
附带说明,使用“O”、“l”等名称命名变量不是一个好习惯。
-
@sgar91 OpenCv 只有 VC10 库。是否有可能只有这不起作用而其他一切都很好?好难过。。
-
@lightalchemist 谢谢,但正如我提到的,我从 OpenCV 教程中复制了它:)
-
ostream是 CPP Runtime 的核心类之一。它的实现在不同版本的VC中有所不同。 OpenCV 代码可以工作,但 CPP 运行时的功能会发生冲突。另一种方法(艰难的方法)是使用 VS 2012 重新编译 OpenCV
标签: c++ opencv visual-studio-2012