Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MinMaxIdx function does not return the correct index. #1151

Closed
chronicom opened this issue Feb 19, 2024 · 2 comments
Closed

MinMaxIdx function does not return the correct index. #1151

chronicom opened this issue Feb 19, 2024 · 2 comments
Labels

Comments

@chronicom
Copy link

chronicom commented Feb 19, 2024

The problem seems to me a typo in the code.

func MinMaxIdx(input Mat) (minVal, maxVal float32, minIdx, maxIdx int) {
	var cMinVal C.double
	var cMaxVal C.double
	var cMinIdx C.int
	var cMaxIdx C.int

	C.Mat_MinMaxIdx(input.p, &cMinVal, &cMaxVal, &cMinIdx, &cMaxIdx)

	return float32(cMinVal), float32(cMaxVal), int(minIdx), int(maxIdx)
}

In stead of returning

float32(cMinVal), float32(cMaxVal), int(minIdx), int(maxIdx)

I guess it should be returning

float32(cMinVal), float32(cMaxVal), int(cMinIdx), int(cMaxIdx)

Moreover, the opencv version of MinMaxIdx returns the indexs in the form of an array of size corresponding to the dimension of the input mat. Here the index is simply a scalar. Does it mean it is a linearized version of the nd-index?

@HIGHER98
Copy link

Nice spot on the typo! Besides the name of the return type, it also seems that an array should be returned with mat.dims elements. This array should always contain at least two elements as per the OpenCV spec:

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. In OpenCV (following MATLAB) each array has at least 2 dimensions, i.e. single-column matrix is Mx1 matrix (and therefore minIdx/maxIdx will be (i1,0)/(i2,0)) and single-row matrix is 1xN matrix (and therefore minIdx/maxIdx will be (0,j1)/(0,j2)).

@deadprogram
Copy link
Member

Released as part of 0.36 so now closing. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants