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.
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.The
.ataccessor functions are very meticulous, requiring very exact data types. Some compilers ignore these issues, while others catch it early.Rather than referencing the elements with
matrix.at<int>(row, col),CV_16Umakes reference to theunsigned shortdata type. Therefore, the elements can be accessed withmatrix.at<unsigned short>(row, col).