Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6925341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:46:39+00:00 2026-05-27T10:46:39+00:00

Using OpenCV 2.3.1. I am running cv::minMaxLoc() and it is returning the point (-1,

  • 0

Using OpenCV 2.3.1. I am running cv::minMaxLoc() and it is returning the point (-1, -1) for both the minimum and maximum location, with 0 as the value for both. What does this mean?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:46:39+00:00Added an answer on May 27, 2026 at 10:46 am

    Below are the relevant sections of code for the minMaxLoc function:

    static void ofs2idx(const Mat& a, size_t ofs, int* idx)
    {
        int i, d = a.dims;
        if( ofs > 0 )
        {
            ofs--;
            for( i = d-1; i >= 0; i-- )
            {
                int sz = a.size[i];
                idx[i] = (int)(ofs % sz);
                ofs /= sz;
            }
        }
        else
        {
            for( i = d-1; i >= 0; i-- )
                idx[i] = -1;
        }
    }
    
    }
    
    void cv::minMaxIdx(InputArray _src, double* minVal,
                       double* maxVal, int* minIdx, int* maxIdx,
                       InputArray _mask)
    {
        Mat src = _src.getMat(), mask = _mask.getMat();
        int depth = src.depth(), cn = src.channels();
    
        CV_Assert( (cn == 1 && (mask.empty() || mask.type() == CV_8U)) ||
                   (cn >= 1 && mask.empty() && !minIdx && !maxIdx) );
        MinMaxIdxFunc func = minmaxTab[depth];
        CV_Assert( func != 0 );
    
        const Mat* arrays[] = {&src, &mask, 0};
        uchar* ptrs[2];
        NAryMatIterator it(arrays, ptrs);
    
        size_t minidx = 0, maxidx = 0;
        int iminval = INT_MAX, imaxval = INT_MIN;
        float fminval = FLT_MAX, fmaxval = -FLT_MAX;
        double dminval = DBL_MAX, dmaxval = -DBL_MAX;
        size_t startidx = 1;
        int *minval = &iminval, *maxval = &imaxval;
        int planeSize = (int)it.size*cn;
    
        if( depth == CV_32F )
            minval = (int*)&fminval, maxval = (int*)&fmaxval;
        else if( depth == CV_64F )
            minval = (int*)&dminval, maxval = (int*)&dmaxval;
    
        for( size_t i = 0; i < it.nplanes; i++, ++it, startidx += planeSize )
            func( ptrs[0], ptrs[1], minval, maxval, &minidx, &maxidx, planeSize, startidx );
    
        if( minidx == 0 )
            dminval = dmaxval = 0;
        else if( depth == CV_32F )
            dminval = fminval, dmaxval = fmaxval;
        else if( depth <= CV_32S )
            dminval = iminval, dmaxval = imaxval;
    
        if( minVal )
            *minVal = dminval;
        if( maxVal )
            *maxVal = dmaxval;
    
        if( minIdx )
            ofs2idx(src, minidx, minIdx);
        if( maxIdx )
            ofs2idx(src, maxidx, maxIdx);
    }    
    
    void cv::minMaxLoc( InputArray _img, double* minVal, double* maxVal,
                    Point* minLoc, Point* maxLoc, InputArray mask )
    {
        Mat img = _img.getMat();
        CV_Assert(img.dims <= 2);
    
        minMaxIdx(_img, minVal, maxVal, (int*)minLoc, (int*)maxLoc, mask);
        if( minLoc )
            std::swap(minLoc->x, minLoc->y);
        if( maxLoc )
            std::swap(maxLoc->x, maxLoc->y);
    }
    

    Judging from the code flow it appears you have the case of minidx equal to zero, which then sets dminval = dmaxval = 0. Also, within the ofs2idx function, when minidx (i.e., ofs parameter in ofs2idx) is equal to zero the logic sets the min and max points to (-1, -1) (i.e., idx[i] = -1;). This might happen if your matrix has no elements. What is the size of the matrix you are trying to use?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody know how does it work and how to do it using OpenCV?
This is simple text detection video made using an opencv. Any ideas how was
am trying to calculate mean and variance using 3X3 window over image(hXw) in opencv...here
I am using opencv with opencvsharp. When doing a matchtemplate and afterwards minmaxloc I
I'm implementing the component labelling algorithm as in this paper using python and opencv.
Using OpenCV, saving a CvMat structure into a YAML file on the disk is
I'm using Opencv's K-means implementation to cluster a large set of 8-dimensional vectors. They
I've been using openCV quite a bit lately and I'm amazed at how fast
I'm doing background subtraction using opencv. The problem is the foreground object is not
How can I subtract one image from another using openCV? Ps.: I coudn't use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.