I have an issue when creating a new (sub)matrix that is taken from a bigger matrix and I was hoping someone could lend me a helping hand.
I have narrowed the problem down to the following small code snippet:
cv::Mat* rightBestX;
rightBestX = new cv::Mat(4, 4, CV_16UC1); // short matrix
// fill rightBestX matrix with values
const cv::Rect r2(0, 0, 2, 2);
cv::Mat x = rightBestX->operator()(r2);
cv::Mat_<short> leftBestXRegion = x; // x is not equal to cv::Mat_<short>, according template<typename _Tp> inline Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat& m)
//cv::Mat_<short> leftBestXRegion = results.leftBestX->operator()(r2);
The above seems to work for float typed matrices, but not when I use short.
The idea is to NOT copy the data but use the data reference from rightBestX. It is successfully copied to x. However, when executing the last line of code, it is lost (different from that of x). Also the refcount is 2 for x, but 1 for leftBestXRegion...
Again, this works for floats. Does anyone have an idea what can be wrong here?
Try using ushort
instead of short
. Also, check out that you are filling your matrix correctly (I am just saying that because I ran it and it works fine for me even with short
)