OpenCV ref count: function returning cv::Mat?
I am tracing a strange bug in my very simple code, and I suspect that I am using cv::Mat
in a wrong way, although with reference counting, there is not much that should go wrong.
My code is this:
cv::Mat rowwise_maximum(const cv::Mat& src, int32_t width)
{
cv::Mat dest = src.clone();
for(int row = 0; row < dest.rows; ++row)
{
for(int col = 0; col < dest.cols; ++col)
{
dest.at< double >(row, col) = 0.5 * src.at< double >(row, col);
}
}
std::cout << "ok" << std::endl;
return dest;
}
// call
cv::Mat max_foo = rowwise_maximum(thresholded, 7);
I am pretty sure that the depth of src
is CV_64F
and therefore the way I use at
is correct. I observe a program crash after leaving the program block calling this code, and the debugger displays max_foo.refcount
to be 0.
I would expect it to be 1 ...
Can someone provide me a hint?
Stupid me ... see comment below the accepted answer. The code above is ok, it's my assumption about the depth which was wrong. I used 'cv::matchTemplate' before, and this gives me a 32 bit floating point image, not 64 bit ...