Ask Your Question

# Revision history [back]

### Android - Does OpenCV4Android support sortIdx?

I'm attempting to take this guide and modify it to get multiple matches : http://stackoverflow.com/questions/17001083/opencv-template-matching-example-in-android/17516753#17516753

So I started looking around since it seems like someone else would have done that. I came across Python examples using NumPY

result = cv2.matchTemplate(img,template,cv.CV_TM_SQDIFF)

#the get the best match fast use this:
(min_x,max_y,minloc,maxloc) = cv2.minMaxLoc(result)
(x,y) = minloc

#get all the matches:
result2 = np.reshape(result, result.shape*result.shape)
sort = np.argsort(result2)
(y1, x1) = np.unravel_index(sort, result.shape) #best match
(y2, x2) = np.unravel_index(sort, result.shape) #second best match


and iOS examples and that brought me to cv::sortIdx.

C++: void sortIdx(InputArray src, OutputArray dst, int flags)

Python: cv2.sortIdx(src, flags[, dst]) → dst
Parameters:

src – input single-channel array.
dst – output integer array of the same size as src.
flags –

operation flags that could be a combination of the following values:
CV_SORT_EVERY_ROW each matrix row is sorted independently.
CV_SORT_EVERY_COLUMN each matrix column is sorted independently; this flag and the previous one are mutually exclusive.
CV_SORT_ASCENDING each matrix row is sorted in the ascending order.
CV_SORT_DESCENDING each matrix row is sorted in the descending order; his flag and the previous one are also mutually exclusive.

The function sortIdx sorts each matrix row or each matrix column in the ascending or descending order. So you should pass two operation flags to get desired behaviour. Instead of reordering the elements themselves, it stores the indices of sorted elements in the output array.


But I can't find any info on if there is a similar method for OpenCV4Android.