[英]OpenCV error for accessing cv::Mat data
For any Mat type that I use with allowable types, I get an an error like below when I try to do some assignment or write to stream etc. It happens on MSVC++ 2010 express compiler, it does not happen with gnu g++ compiler. 对于我使用允许类型的任何Mat类型,当我尝试做一些赋值或写入流等时,我得到如下的错误。它发生在MSVC ++ 2010 express编译器上,gnu g ++编译器不会发生这种情况。
example flawed usage: 示例有缺陷的用法:
Mat M = Mat::zeros( image.size(), DataType<int>::type );
std::cout << M.at<int>( 0,0 ) << std::endl; // error
// OR
int x = M.at<int>( 0,0 ); // error
the two errors fired together: 这两个错误一起发生:
on popup window 在弹出窗口上
Unhandled exception at <some hex adress> in test.exe:Microsoft C++ exception: cv:xception at memory location <some hex adress>
and on console window 并在控制台窗口上
OpenCV Error: Assertion failed ... \mat.hpp, line 537
Any suggestions? 有什么建议?
Make the matrix data type CV_16U
. 使矩阵数据类型为
CV_16U
。
The .at
accessor functions are very meticulous, requiring very exact data types. .at
访问器功能非常细致,需要非常精确的数据类型。 Some compilers ignore these issues, while others catch it early. 有些编译器会忽略这些问题,而其他编译器则会提前发现。
Rather than referencing the elements with matrix.at<int>(row, col)
, CV_16U
makes reference to the unsigned short
data type. 而不是参考与元素
matrix.at<int>(row, col)
, CV_16U
参考了unsigned short
的数据类型。 Therefore, the elements can be accessed with matrix.at<unsigned short>(row, col)
. 因此,可以使用
matrix.at<unsigned short>(row, col)
访问元素。
I don't believe openCV has an int data type image. 我不相信openCV有一个int数据类型的图像。
The integer type is generally CV_16s, ie 16bit short, so use 整数类型一般为CV_16s,即16位短,所以使用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.