Learn Python OpenCV cv2.minMaxLoc() by Examples – OpenCV Tutorial

By | October 14, 2020

OpenCV cv2.minMaxLoc() is often used to find the maximum and minimum value in a numpy array. In this tutorial, we will use an example to show you how to use this function.

Look at this example:

import numpy as np
import cv2
a=np.array([[1,2,3,4],[5,67,8,9]])

We have created a numpy array a, which is 2*4.

In order to find the maximum and minimum value in a, we can do like this:

min_val,max_val,min_indx,max_indx=cv2.minMaxLoc(a)

print(min_val,max_val,min_indx,max_indx)

cv2.minMaxLoc() will return four values:

min_val: the minimum value

max_val: the maximum value

min_index: the index of minimum value in a

max_indx: the index of maximum value in a

Run this code, you will get:

1.0 67.0 (0, 0) (1, 1)

Leave a Reply