cv::Mat of large integers
8-bit, c++, integer, opencv
Solution
When you define matrix as `CV_8UC1` you define that every element must be 8 bit. That means that you can store only value from 0 to 255. If you want to use a big number you should define matrix as `CV_32UC1` for `unsigned integers` or `CV_32SC1` for `signed integers`. Also you should to store a value as `int` instead of `char` and read it in appropriate way.
More correct code is
Mat matrix(6,10,CV_32SC1);
matrix.at<int>(0,0) = 2942584;
cout << (int)matrix.at<int>(0,0);
One more thing: format of the matrix element is the following
CV_<NUMBER_OF_BITS><SIGNED/UNSIGNED>C<NUMBER_OF_CHANNELS>
Problem
I am struggling with putting large integers, such as 2942584, in a cv Mat. The only type accepting it was CV_8UC1, but it changes the value from 2942584 to 120 (well in 8 bits obviously). But is there anyway to have the original value in a cv Mat?? Here is the simple code if it helps: ``` Mat matrix(6,10,CV_8UC1); matrix.at<char>(0,0) = 2942584; cout << (int)matrix.at<char>(0,0); ``` output: ``` 120 ```