繁体   English   中英

用于访问cv :: Mat数据的OpenCV错误

[英]OpenCV error for accessing cv::Mat data

对于我使用允许类型的任何Mat类型,当我尝试做一些赋值或写入流等时,我得到如下的错误。它发生在MSVC ++ 2010 express编译器上,gnu g ++编译器不会发生这种情况。

示例有缺陷的用法:

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

这两个错误一起发生:

在弹出窗口上

Unhandled exception at <some hex adress> in test.exe:Microsoft C++ exception: cv:xception at memory location <some hex adress>

并在控制台窗口上

OpenCV Error: Assertion failed ... \mat.hpp, line 537

有什么建议?

使矩阵数据类型为CV_16U

.at访问器功能非常细致,需要非常精确的数据类型。 有些编译器会忽略这些问题,而其他编译器则会提前发现。

而不是参考与元素matrix.at<int>(row, col)CV_16U参考了unsigned short的数据类型。 因此,可以使用matrix.at<unsigned short>(row, col)访问元素。

我不相信openCV有一个int数据类型的图像。
整数类型一般为CV_16s,即16位短,所以使用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM