我正在使用brisk进入我的android应用程序。代码是:
public boolean runBRISK(String filename1, String filename2)
{
BRISK detectorAndExtractor = BRISK.create();
final MatOfKeyPoint keyPointsLarge = new MatOfKeyPoint();
final MatOfKeyPoint keyPointsSmall = new MatOfKeyPoint();
Mat largeImage = Imgcodecs.imread(filename1, Imgcodecs.IMREAD_COLOR);
Mat smallImage = Imgcodecs.imread(filename2, Imgcodecs.IMREAD_COLOR);
detectorAndExtractor.detect(largeImage, keyPointsLarge);
detectorAndExtractor.detect(smallImage, keyPointsSmall);
//System.out.println("keyPoints.size() : "+keyPointsLarge.size());
//System.out.println("keyPoints2.size() : "+keyPointsSmall.size());
Mat descriptorsLarge = new Mat();
Mat descriptorsSmall = new Mat();
detectorAndExtractor.compute(largeImage, keyPointsLarge, descriptorsLarge);
detectorAndExtractor.compute(smallImage, keyPointsSmall, descriptorsSmall);
//System.out.println("descriptorsA.size() : "+descriptorsLarge.size());
//System.out.println("descriptorsB.size() : "+descriptorsSmall.size());
MatOfDMatch matches = new MatOfDMatch();
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);
matcher.match(descriptorsLarge, descriptorsSmall, matches);
System.out.println("matches.size() : "+matches.size());
MatOfDMatch matchesFiltered = new MatOfDMatch();
List<DMatch> matchesList = matches.toList();
List<DMatch> bestMatches= new ArrayList<DMatch>();
Double max_dist = 0.0;
Double min_dist = 100.0;
for (int i = 0; i < matchesList.size(); i++)
{
Double dist = (double) matchesList.get(i).distance;
if (dist < min_dist && dist != 0)
{
min_dist = dist;
}
if (dist > max_dist)
{
max_dist = dist;
}
}
//System.out.println("max_dist : "+max_dist);
//System.out.println("min_dist : "+min_dist);
if(min_dist > 50 )
{
//System.out.println("No match found");
//System.out.println("Just return ");
return false;
}
double threshold = 3 * min_dist;
double threshold2 = 2 * min_dist;
if (threshold > 75)
{
threshold = 75;
}
else if (threshold2 >= max_dist)
{
threshold = min_dist * 1.1;
}
else if (threshold >= max_dist)
{
threshold = threshold2 * 1.4;
}
//System.out.println("Threshold : "+threshold);
for (int i = 0; i < matchesList.size(); i++)
{
Double dist = (double) matchesList.get(i).distance;
if (dist < threshold)
{
bestMatches.add(matches.toList().get(i));
//System.out.println(String.format(i + " best match added : %s", dist));
}
}
matchesFiltered.fromList(bestMatches);
System.out.println("matchesFiltered.size() : " + matchesFiltered.size());
if(matchesFiltered.rows() >= 1) //TODO >= 4
{
System.out.println("match found");
return true;
}
else
{
return false;
}
}
图片如下:
图像#0
图像#1与#0进行比较
图像#2与#0比较
图像#1和#2几乎相同,唯一的区别是颜色。
问题是,当我将它们与图像0进行比较时,得到99个与图像1最匹配的结果,86个与图像2最匹配的结果。但是,图像#0和#2共享主对象的相同颜色(深紫色)。
如何添加色差检测以改进特征匹配?
暂无答案!
目前还没有任何答案,快来回答吧!