如何使用 openCV (java) 从最佳匹配列表中获取像素坐标?
How to get pixel coordinates from a list of best matches using openCV (java)?
我正在使用 openCV (java) 并且我有一个最佳匹配列表。这是我的代码:
final MatOfKeyPoint keyPoints1 = new MatOfKeyPoint();
final MatOfKeyPoint keyPoints2 = new MatOfKeyPoint();
...
MatOfDMatch matches = new MatOfDMatch();
...
List<DMatch> matchesList = matches.toList();
List<DMatch> bestMatches = new ArrayList<DMatch>();
for (int i = 0; i < matchesList.size(); i++)
{
Double dist = (double) matchesList.get(i).distance;
if (dist < threshold)
{
bestMatches.add(matches.toList().get(i));
}
}
我知道我必须使用列车和查询描述符的索引,但我不知道如何使用。
我试过这些但没有用,因为 MatOfKeyPoint
不能像 Java.
中的数组一样访问
for(int i = 0; i < bestMatches.size(); i++)
{
keyPoints1[bestMatches.get(i).queryIdx].pt;
keyPoints2[bestMatches.get(i).trainIdx].pt;
}
如何找到像素坐标?
LinkedList<Point> queryList = new LinkedList<Point>();
LinkedList<Point> trainList = new LinkedList<Point>();
List<KeyPoint> keypoints_queryList = keyPoints1.toList();
List<KeyPoint> keypoints_trainList = keyPoints2.toList();
for (int i = 0; i < bestMatches.size(); i++) {
queryList.addLast(keypoints_queryList.get(bestMatches.get(i).queryIdx).pt);
trainList.addLast(keypoints_trainList.get(bestMatches.get(i).trainIdx).pt);
}
MatOfPoint2f queryCoords = new MatOfPoint2f();
queryCoords.fromList(queryList);
MatOfPoint2f trainCoords = new MatOfPoint2f();
trainCoords.fromList(trainList);
希望对您有所帮助!!
我正在使用 openCV (java) 并且我有一个最佳匹配列表。这是我的代码:
final MatOfKeyPoint keyPoints1 = new MatOfKeyPoint();
final MatOfKeyPoint keyPoints2 = new MatOfKeyPoint();
...
MatOfDMatch matches = new MatOfDMatch();
...
List<DMatch> matchesList = matches.toList();
List<DMatch> bestMatches = new ArrayList<DMatch>();
for (int i = 0; i < matchesList.size(); i++)
{
Double dist = (double) matchesList.get(i).distance;
if (dist < threshold)
{
bestMatches.add(matches.toList().get(i));
}
}
我知道我必须使用列车和查询描述符的索引,但我不知道如何使用。
我试过这些但没有用,因为 MatOfKeyPoint
不能像 Java.
for(int i = 0; i < bestMatches.size(); i++)
{
keyPoints1[bestMatches.get(i).queryIdx].pt;
keyPoints2[bestMatches.get(i).trainIdx].pt;
}
如何找到像素坐标?
LinkedList<Point> queryList = new LinkedList<Point>();
LinkedList<Point> trainList = new LinkedList<Point>();
List<KeyPoint> keypoints_queryList = keyPoints1.toList();
List<KeyPoint> keypoints_trainList = keyPoints2.toList();
for (int i = 0; i < bestMatches.size(); i++) {
queryList.addLast(keypoints_queryList.get(bestMatches.get(i).queryIdx).pt);
trainList.addLast(keypoints_trainList.get(bestMatches.get(i).trainIdx).pt);
}
MatOfPoint2f queryCoords = new MatOfPoint2f();
queryCoords.fromList(queryList);
MatOfPoint2f trainCoords = new MatOfPoint2f();
trainCoords.fromList(trainList);
希望对您有所帮助!!