OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Mon, 09 Mar 2015 10:45:25 -0500Android - Does OpenCV4Android support sortIdx?http://answers.opencv.org/question/56769/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[0]*result.shape[1])
sort = np.argsort(result2)
(y1, x1) = np.unravel_index(sort[0], result.shape) #best match
(y2, x2) = np.unravel_index(sort[1], 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.Wed, 04 Mar 2015 13:31:53 -0600http://answers.opencv.org/question/56769/android-does-opencv4android-support-sortidx/Comment by Mytheral for <p>I'm attempting to take this guide and modify it to get multiple matches : <a href="http://stackoverflow.com/questions/17001083/opencv-template-matching-example-in-android/17516753#17516753">http://stackoverflow.com/questions/17...</a></p>
<p>So I started looking around since it seems like someone else would have done that. I came across Python examples using NumPY </p>
<pre><code>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[0]*result.shape[1])
sort = np.argsort(result2)
(y1, x1) = np.unravel_index(sort[0], result.shape) #best match
(y2, x2) = np.unravel_index(sort[1], result.shape) #second best match
</code></pre>
<p>and iOS examples and that brought me to cv::sortIdx.</p>
<pre><code>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.
</code></pre>
<p>But I can't find any info on if there is a similar method for OpenCV4Android.</p>
http://answers.opencv.org/question/56769/android-does-opencv4android-support-sortidx/?comment=57086#post-id-57086You rock man! Thanks.Mon, 09 Mar 2015 10:45:25 -0500http://answers.opencv.org/question/56769/android-does-opencv4android-support-sortidx/?comment=57086#post-id-57086Comment by berak for <p>I'm attempting to take this guide and modify it to get multiple matches : <a href="http://stackoverflow.com/questions/17001083/opencv-template-matching-example-in-android/17516753#17516753">http://stackoverflow.com/questions/17...</a></p>
<p>So I started looking around since it seems like someone else would have done that. I came across Python examples using NumPY </p>
<pre><code>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[0]*result.shape[1])
sort = np.argsort(result2)
(y1, x1) = np.unravel_index(sort[0], result.shape) #best match
(y2, x2) = np.unravel_index(sort[1], result.shape) #second best match
</code></pre>
<p>and iOS examples and that brought me to cv::sortIdx.</p>
<pre><code>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.
</code></pre>
<p>But I can't find any info on if there is a similar method for OpenCV4Android.</p>
http://answers.opencv.org/question/56769/android-does-opencv4android-support-sortidx/?comment=56778#post-id-56778well, that was not so hard to find: http://docs.opencv.org/java/org/opencv/core/Core.html#sortIdx(org.opencv.core.Mat,%20org.opencv.core.Mat,%20int)Wed, 04 Mar 2015 14:10:39 -0600http://answers.opencv.org/question/56769/android-does-opencv4android-support-sortidx/?comment=56778#post-id-56778