crash in Mat::release()
Hi, I have a function that creates a histogram:
double median_(const cv::Mat& channel)
{
double m = (channel.rows*channel.cols) / 2;
int bin = 0;
double med = -1.0;
int histSize = 256;
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true;
bool accumulate = false;
cv::Mat hist;
cv::calcHist(&channel, 1, 0, cv::Mat(), hist, 1, &histSize, &histRange, uniform, accumulate);
for (int i = 0; i < histSize && med < 0.0; ++i)
{
bin += cvRound(hist.at< float >(i));
if (bin > m && med < 0.0)
med = i;
}
hist.release();
return med;
}
Calling hist.release() is crashing. Can someone help please?
Do not call
release()
, let it go out of scope.Why do you put
&
in front of channel argument? There is usually no reason to passcv::Mat
pointers.Hi Der, thanks for your reply... Ignore the sample above and check the simple sample below: void f6() { cv::Mat src = cv::imread("d:\file.jpg"); cv::Mat scaled; float scale = 0.25; cv::resize(src, scaled, cv::Size(), scale, scale, CV_INTER_CUBIC); }
The function crashes while the destruction of cv::Mat is executed. It crashes in the function deallocate() in Mat::release(). I don't understand the reason for the crash.