Reputation: 459
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?
Upvotes: 3
Views: 6595
Reputation: 4983
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)
.
Upvotes: 7
Reputation: 96167
I don't believe openCV has an int data type image.
The integer type is generally CV_16s, ie 16bit short, so use
Upvotes: 0