Ask Your Question
0

cv::minMaxLoc argument problem

asked 2015-09-19 07:59:02 -0600

OrkunK gravatar image

updated 2015-09-19 08:04:37 -0600

I'm trying to use cv::minMaxLoc to find minium and maximum values and points in a one-dimensional array but I can't compile the source.

void main(void)
{
    cv::Mat array1D = cv::Mat(1, 800, CV_32FC1, cv::Scalar(0));
    double minVal;
    double maxVal;
    int minIdx;
    int maxIdx;
    // ....
    // putting an image projection to array1D and I can draw and view it's histogram
    // ....
    cv::minMaxLoc(array1D, &minVal, &maxVal, &minIdx, &maxIdx);
}

But I'm getting, error C2665: 'cv::minMaxLoc' : none of the 2 overloads could convert all the argument type when I change the cv::minMaxLoc line to cv::minMaxLoc(array1D, &minVal, &maxVal);, there is no error. I also tried casting the idx addresses with (int *) and also tried too cv::minMaxLoc(array1d, &minVal, &maxVal, &minIdx, &maxIdx, cv::Mat()) and result is same.

edit retag flag offensive close merge delete

Comments

i guess, you wanted minMaxIdx() , not minMaxLoc()

berak gravatar imageberak ( 2015-09-19 09:49:57 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-09-19 08:40:15 -0600

LorenaGdL gravatar image

updated 2015-09-19 08:40:51 -0600

Have a careful look at the documentation. The data type of the minIdx and maxIdx has to be a Point when using a Mat input. Therefore, your code will work if modified as follows:

void main(void)
{
    cv::Mat array1D = cv::Mat(1, 800, CV_32FC1, cv::Scalar(0));
    double minVal;
    double maxVal;
    Point minIdx;
    Point maxIdx;
    // ....
    // putting an image projection to array1D and I can draw and view it's histogram
    // ....
    cv::minMaxLoc(array1D, &minVal, &maxVal, &minIdx, &maxIdx);
}

As you're using a one-row matrix, just discard the returned y-coordinates of the Points and use the x-coordinates

edit flag offensive delete link more

Comments

I didn't look at documentation but in the function prototype core.hpp just pasting it without any changes CV_EXPORTS void minMaxLoc(const SparseMat& a, double* minVal, double* maxVal, int* minIdx=0, int* maxIdx=0); at line 3629. But there is another one too as your said. Anyway thanks..

OrkunK gravatar imageOrkunK ( 2015-09-21 11:02:20 -0600 )edit

That is for sparse matrices, it won't work with normal matrices ;)

LorenaGdL gravatar imageLorenaGdL ( 2015-09-21 11:18:53 -0600 )edit

you can use function: void minMaxLoc(InputArray src, CV_OUT double* minVal, CV_OUT double* maxVal=0, CV_OUT Point* minLoc=0, CV_OUT Point* maxLoc=0, InputArray mask=noArray()); and note that the function don't work with multi-channel arrays, so you should use function Mat:reshape() to reinterpret the arrays as a single-channel.

DucPham gravatar imageDucPham ( 2018-04-09 13:40:09 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-09-19 07:59:02 -0600

Seen: 7,441 times

Last updated: Sep 19 '15