我正在尝试使用 OpenCV 的 DescriptorMatcher 匹配 2 个相反的图像,但没有成功。 图片是:http://i61.tinypic.com/28whu0g.jpg (从左到右)和 http://i61.tinypic.com/x35vte.jpg (从右到左)。
我的代码与我在 StackOverflow 和网络上看到的许多示例非常相似,但我仍然无法匹配。
String firstImageSourcePath = "RTL_IMAGE_PATH";
String secondImageSourcePath = "LTR_IMAGE_PATH";
Mat firstImageSrcImgMat = Highgui.imread(firstImageSourcePath);
Mat secondImageSrcImgMat = Highgui.imread(firstImageSourcePath);
if (firstImageSrcImgMat.empty() || secondImageSrcImgMat.empty()) {
System.out.println("Failed to load images");
return;
}
System.out.println("Loaded image at " + firstImageSourcePath + " and " + secondImageSourcePath);
FeatureDetector featureDetector = FeatureDetector.create(FeatureDetector.BRISK);
MatOfKeyPoint firstImgMatOfKeyPoints = new MatOfKeyPoint();
MatOfKeyPoint secondImgMatOfKeyPoints = new MatOfKeyPoint();
featureDetector.detect(firstImageSrcImgMat, firstImgMatOfKeyPoints);
featureDetector.detect(secondImageSrcImgMat, secondImgMatOfKeyPoints);
System.out.println("Detected " + firstImgMatOfKeyPoints.size() + " and " + secondImgMatOfKeyPoints + " blobs in the images");
List<KeyPoint> firstImgKeyPoints = firstImgMatOfKeyPoints.toList();
List<KeyPoint> secondImgKeyPoints = secondImgMatOfKeyPoints.toList();
System.out.println("First Image key points: " + firstImgKeyPoints);
System.out.println("Second Image key points: " + secondImgKeyPoints);
Mat firstImgDescriptors = new Mat();
Mat secondImgDescriptors = new Mat();
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.BRISK);
extractor.compute(firstImageSrcImgMat, firstImgMatOfKeyPoints, firstImgDescriptors);
extractor.compute(secondImageSrcImgMat, secondImgMatOfKeyPoints, secondImgDescriptors);
System.out.println("descriptorsA.size() : " + firstImgDescriptors.size());
System.out.println("descriptorsB.size() : " + secondImgDescriptors.size());
MatOfDMatch matches = new MatOfDMatch();
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT); // BRUTEFORCE_HAMMINGLUT
matcher.match(firstImgDescriptors, secondImgDescriptors, matches);
System.out.println("matches.size() : " + matches.size());
System.out.println("matches : " + matches);
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 > 0)
System.out.println("dist : " + dist);
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, min_dist under minimum value");
return;
}
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) {
System.out.println("match found");
} else {
System.out.println("match not found");
}
任何提示我做错了什么?
最佳答案
正如@Iwillnotexist-Idonotexist 所述,第一个问题是您应用的阈值。尝试使用不依赖于表现不佳的描述符之间的距离的阈值,因为一些描述符比其他描述符更具辨别力。我认为这会给你更好的结果。我建议您使用 D. Lowe 在 SIFT 的论文中提出的 Ratio Test。 请查看第 7.1 节:http://cs.ubc.ca/~lowe/papers/ijcv04.pdf
第二个问题是您正在使用 BRISK 来检测图像中的特征。这个 OpenCV 实现有错误(你可以在这里查看:http://code.opencv.org/issues/3976)所以尝试使用另一个 FeatureDetector,比如 FAST、ORB 等……(描述符很好,所以你可以继续使用它)
我最终在您的图片中进行了测试,并设法使用不同的检测器/描述符获得了一些结果: (没有匹配的关键点 -> 黄色)
BRISK 检测器和描述符:
以 BRISK 作为描述符的 ORB 检测器:
ORB 检测器和描述符
所有结果都是使用比率测试去除错误匹配获得的。 希望对您有所帮助!
编辑:
BruteForceMatcher<Hamming> matcher;
vector< vector<DMatch> > matches;
vector <DMatch> goodMatches;
matcher.knnMatch(imgDescriptors1, imgDescriptors2, matches, 2);
// Ratio Test
for (unsigned int matchIdx = 0; matchIdx < matches.size(); ++matchIdx)
{
const float ratio = 0.8; // As in Lowe's paper (can be tuned)
if (matches[matchIdx][0].distance < ratio * matches[matchIdx][1].distance)
{
goodMatches.push_back(matches[matchIdx][0]);
}
}
关于java - OpenCV - Java - 使用 DescriptorMatcher 与 2 个相反的图像不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26860992/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
我正在尝试使用ruby和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po