对于对象识别/检测,为了找到好的匹配,我使用了以下方法。
在这里,我两次找到单应性,从第一个单应性使用输出掩码作为过滤器来查找第二个单应性的输入关键点。
我正在使用特征描述符和提取器选项,如下所示
FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
matcher.match(descriptorRef, descriptor, matches);
List<DMatch> matchesList = matches.toList();
keypoints_RefList = keypointsRef.toList();
keypoints_List = keypoints.toList();
第一次计算 - 使用匹配中的所有关键点
///////// first calculation
for (int i = 0; i < matchesList.size(); i++) {
objList1.addLast(keypoints_RefList.get(matchesList.get(i).queryIdx));
sceneList1.addLast(keypoints_List.get(matchesList.get(i).trainIdx));
}
obj1.fromList(objList1);
scene1.fromList(sceneList1);
Mat hg1 = Calib3d.findHomography(obj1, scene1, 8, 10, mask1);
第二次计算 - 使用 mask1 的掩码值仅使用匹配中的内部关键点
///////// second calculation
for(int i=0; i < mask1.rows(); i++){
if(mask1.get(i,0)[0] == 1){ ////////this time add only where mask1 is 1
objList.addLast(keypoints_RefList.get(matchesList.get(i).queryIdx));
sceneList.addLast(keypoints_List.get(matchesList.get(i).trainIdx));
}
}
obj.fromList(objList);
scene.fromList(sceneList);
Mat hg = Calib3d.findHomography(obj, scene, 8, 10, mask);
现在 mask1 和 mask 是
mask1 : [0; 0; 0; 1; 0; 1; 1; 1; 0; 0; 0; 1; 1; 0; 1; 0; 0; 1; 1; 1; 0; 1; 0; 0; 0; 1; 0; 0; 1; 0; 0; 0; 1; 0; 0; 0; 0; 0; 1; 0; 1; 0; 1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 1; 0; 0; 0; 0; 1; 0; 0; 0; 0; 1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 1; 1; 0; 0; 0; 0; 0; 0; 0; 1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 1; 0; 0; 1; 1; 1; 0; 0; 0; 1; 1; 0; 1; 1; 1; 1; 0; 0; 0; 0; 1; 1; 0; 0; 0; 0; 1; 0; 1; 1; 0; 1; 0; 1; 0; 1; 0; 0; 0; 1; 1; 1; 1; 0; 0; 1; 1; 1; 0]
mask : [0; 1; 0; 0; 1; 1; 1; 1; 0; 0; 1; 1; 1; 1; 1; 1; 1; 0; 0; 1; 1; 0; 0; 0; 0; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 0; 0; 0; 0; 0; 0; 1; 1; 1; 1; 1; 1; 1; 1]
现在,由于第二个单应性的所有输入都是内点,掩码值应该全部为 1,但绝不会全部为 1。有时我在掩码中得到更多的零。
单应性 3x3 输出 hg1 和 hg 有一些负值是可以接受的还是有什么问题?
我应该使用什么方法来过滤好的关键点,以便获得正确的单应矩阵并且透视投影是正确的?