Java Code Examples for org.opencv.core.MatOfDMatch.toList()

The following are Jave code examples for showing how to use toList() of the org.opencv.core.MatOfDMatch class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: zooracle   File: KMeansMatcher.java   View Source Code Vote up 4 votes
public ArrayList<int[]> getBestMatches()
{
	
	List<MatOfDMatch> matches = new ArrayList<MatOfDMatch>();
	int[] matchMatrix = new int[numPhotos];
    ArrayList<ArrayList<Integer>> clusterImageMap = model.getClusterImageMap();
    ArrayList<int[]> bestMatchArray = new ArrayList<int[]>();
    
	//get current query image keypoints and descriptors, match with k-means centroid descriptors
	featureDetector.detect(queryImage, queryImageKeypoints);
	descriptorExtractor.compute(queryImage, queryImageKeypoints, queryImageDescriptors);
	matcher.knnMatch(queryImageDescriptors, model.getCentroids(), matches, (int) kMax);
	for (MatOfDMatch mdm : matches)
	{
		for (DMatch dm : mdm.toList())
		{
			int detectedKIndex = dm.trainIdx;
			for (int photoIndex : clusterImageMap.get(detectedKIndex))
				matchMatrix[photoIndex]++;
		}
	}

	//compute n best matches
	int currentBestMatchCount = -1;
	int currentBestMatchIndex = -1;
	for (int i = 0; i < numPhotos; i++)
	{
		currentBestMatchCount = (int) matchMatrix[i];
		currentBestMatchIndex = i;
		bestMatchArray.add(new int[] { currentBestMatchIndex, currentBestMatchCount });
	}
	Collections.sort(bestMatchArray, new Comparator<int[]>()
	{
		public int compare(int[] o1, int[] o2)
		{
			if (o1[1] < o2[1])
				return 1;
			else if (o1[1] > o2[1])
				return -1;
			return 0;
		}
	});
	
	return bestMatchArray;
}