对于我使用允许类型的任何 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)
访问这些元素。 .
关于c++ - 访问 cv::Mat 数据的 OpenCV 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13546151/