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 .at accessor 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_16U makes reference to the unsigned short data type. Therefore, the elements can be accessed with matrix.at<unsigned short>(row, col).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With