Question

Using OpenCV (2.49 binaries) with MSVC 2013, the debug runtime reports a stack corruption when using cv::minMaxIdx in this short code:

    cv::MatND hist;
    int histSize[] = { 256 };
    float range[] = { 0, 256 };
    const float* histRange[] = { range };

    cv::calcHist(&image, 1, { 0 }, cv::Mat(), hist, 1, histSize, histRange, true /* uniform */, true /* accumulate */);
    // this line provokes a stack corruption
    cv::minMaxIdx(hist, nullptr, nullptr, nullptr, &maxIdx);

I can see the histogram in the debugger, all values and variables look correct. The problem does not occur in Release mode but I suspect that's only because the checks are not running. Changing hist to hist.col(0) did not help either.

Was it helpful?

Solution

From OpenCV documentation:

When minIdx is not NULL, it must have at least 2 elements (as well as maxIdx), even if src is a single-row or single-column matrix.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top