我正在使用OpenCV 2.3.1中的Orb特征检测器开展项目.我发现8个不同图像之间的匹配,其中6个非常相似(相机位置相差20厘米,沿线性滑块,因此没有比例或旋转方差),然后从大约45度角拍摄2张图像侧.我的代码在非常相似的图像之间找到了大量精确匹配,但从更不同的角度拍摄的图像几乎没有.我已经包含了我认为是我的代码的相关部分,如果您需要更多信息,请告诉我.
// set parameters
int numKeyPoints = 1500;
float distThreshold = 15.0;
//instantiate detector, extractor, matcher
detector = new cv::OrbFeatureDetector(numKeyPoints);
extractor = new cv::OrbDescriptorExtractor;
matcher = new cv::BruteForceMatcher<cv::HammingLUT>;
//Load input image detect keypoints
cv::Mat img1;
std::vector<cv::KeyPoint> img1_keypoints;
cv::Mat img1_descriptors;
cv::Mat img2;
std::vector<cv::KeyPoint> img2_keypoints
cv::Mat img2_descriptors;
img1 = cv::imread(fList[0].string(), CV_LOAD_IMAGE_GRAYSCALE);
img2 = cv::imread(fList[1].string(), CV_LOAD_IMAGE_GRAYSCALE);
detector->detect(img1, img1_keypoints);
detector->detect(img2, img2_keypoints);
extractor->compute(img1, img1_keypoints, img1_descriptors);
extractor->compute(img2, img2_keypoints, img2_descriptors);
//Match keypoints using knnMatch to find the single best match for each keypoint
//Then cull results …Run Code Online (Sandbox Code Playgroud) 我正在使用OpenCV 2.4.3 c ++接口来查找两个图像之间的匹配点.第一次尝试是使用SURF.唯一的问题是消耗时间,所以我尝试了新的FREAK提取器.使用SURF进行检测和FREAK进行描述,我意识到FREAK将关键点的数量减少到几乎检测到的一半,并且得到的匹配不够.这就是原因,我尝试了FAST以获得更多关键点.结果:
之后,我使用了ORBFeatureDetector,它获得了与FAST相同数量的关键点,但在FREAK提取器之后,每个图像的结果关键点为0.难道我做错了什么?ORB关键点是否与从FAST获得的关键点不同?也许我可以为此开另一个问题,但我有最后一个问题.检测器/提取器的最佳组合是什么才能获得与使用SURF的第一次实验相同的结果,但缩短处理时间?因为虽然我使用了FREAK,但是当我获得更多关键点时,提取器部分也更耗时.
我目前正在使用OpenCV的ORB特征提取器,我确实注意到存储ORB描述符的奇怪(至少对我而言)(它基本上是一个Brief-32,其修改与我的问题无关).由于一些你知道ORB需要使用改良的FAST-9提取的关键点(圆半径= 9个像素;还存储所述关键点的方向),并使用那些具有修饰的附图-32的描述符存储的特征,即关键点表示.
BRIEF(ORB版)的工作原理如下:我们采用31x31像素的补丁(代表一个特征)并创建一堆随机的5x5像素测试点.然后我们采用这些点的对并评估它们的强度,从而基于该对中的第一点的强度是大于还是小于第二点的强度来产生二元决策(0或1).然后我们取所有这些位并使用基本求和公式来构建长度为n的二进制字符串(对于BRIEF-32,我们有32个字节*8 = 256位长的二进制字符串):
SUM(2 (i-1)*bit_pair_test)
其中bit_pair_test是我们从一对测试点的测试中计算出的位值.最终的结果是(对于一组二进制测试(...,0,1,0,1,1)):
(2 0*1)+(2 1*1)+(2 2*0)+(2 3*1)+(2 4*0)+ ...
现在,OpenCV的ORB存储这些位串的方式对我来说是个谜.如果我们查看包含整个图像的描述符的矩阵,其中每一行是单个关键点的单个描述符,我们可以看到每个描述符有32个8位数,这总共产生了Brief-32使用的那些256位存储信息.我不明白为什么我们在32字节中分割这256位.官方文档(http://docs.opencv.org/trunk/doc/py_tutorials/py_feature2d/py_brief/py_brief.html)只说以字节为单位的OpenCV商店这样的描述,但它并不能解释为什么它做到这一点.我已经考虑了三种可能性,但没有排除这些可能是答案的可能性的可能性:
我正在运行Ubuntu 14.04.我试图用openCV 3运行FLANN,但是我收到错误.
通过使用AKAZE和ORB尝试下面的所有内容,但是从我尝试使用ORB的代码.
我使用ORB来查找描述符和关键点.
Ptr<ORB> detector = ORB::create();
std::vector<KeyPoint> keypoints_1, keypoints_2;
Mat descriptors_1, descriptors_2;
detector->detectAndCompute( img_1, noArray(), keypoints_1, descriptors_1 );
detector->detectAndCompute( img_2, noArray(), keypoints_2, descriptors_2 );
Run Code Online (Sandbox Code Playgroud)
使用ORB后,我使用以下代码查找匹配项:
FlannBasedMatcher matcher;
std::vector<DMatch> matches;
matcher.match(descriptors_1, descriptors_2, matches);
Run Code Online (Sandbox Code Playgroud)
代码构建良好和一切.当我运行代码时,我收到此错误:
OpenCV Error: Unsupported format or combination of formats (type=0
) in buildIndex_, file /home/jim/opencv/modules/flann/src/miniflann.cpp, line 315
terminate called after throwing an instance of 'cv::Exception'
what(): /home/jim/opencv/modules/flann/src/miniflann.cpp:315: error: (-210) type=0
in function buildIndex_
Aborted (core dumped)
Run Code Online (Sandbox Code Playgroud)
谁能告诉我为什么?这是OpenCV 3处于BETA状态的问题吗?是否有替代FLANN(BFMatcher除外)
我正在使用SURF描述符进行图像匹配.我打算将给定的图像与图像数据库进行匹配.
import cv2
import numpy as np
surf = cv2.xfeatures2d.SURF_create(400)
img1 = cv2.imread('box.png',0)
img2 = cv2.imread('box_in_scene.png',0)
kp1,des1 = surf.detectAndCompute(img1,None)
kp2,des2 = surf.detectAndCompute(img2,None)
bf = cv2.BFMatcher(cv2.NORM_L1,crossCheck=True)
#I am planning to add more descriptors
bf.add(des1)
bf.train()
#This is my test descriptor
bf.match(des2)
Run Code Online (Sandbox Code Playgroud)
问题bf.match在于我收到以下错误:
OpenCV Error: Assertion failed (type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U)) in batchDistance, file /build/opencv/src/opencv-3.1.0/modules/core/src/stat.cpp, line 3749
Traceback (most recent call last):
File "image_match4.py", line 16, in <module>
bf.match(des2) …Run Code Online (Sandbox Code Playgroud) 我正在使用特征提取(筛选,orb)进行对象检测.
我想从对象的不同视角(训练图像)中提取ORB特征,然后将它们与查询图像进行匹配.
我面临的问题是:如何从不同角度的关键点创建一个良好的单应性,这些关键点当然具有不同大小的图像?
我正在考虑为每个火车图像创建一个单应性,然后说3-4个匹配,然后计算一些"均值"单应...
例如,当您从每个火车图像中说出1-2个匹配时,会出现问题,此时您无法创建甚至1个单应性
创造单应性的代码
//> For each train images with at least some good matches ??
H = findHomography( train, scene, CV_RANSAC );
perspectiveTransform( trainCorners, sceneCorners, H);
Run Code Online (Sandbox Code Playgroud) 所以,我试图在我的Laravel 5.3中运行一个python脚本.
这个功能在我的Controller里面.这只是将数据传递给我的python脚本
public function imageSearch(Request $request) {
$queryImage = 'c:\\\xampp\\\htdocs\\\identificare_api\\\public\\\gallery\\\herbs\\\query.png'; //queryImage
$trainImage = 'c:\\\xampp\\\htdocs\\\identificare_api\\\public\\\gallery\\\herbs\\\2nd.png'; //trainImage
$trainImage1 = 'c:\\\xampp\\\htdocs\\\identificare_api\\\public\\\gallery\\\herbs\\\3rd.png';
$trainImage2 = 'c:\\\xampp\\\htdocs\\\identificare_api\\\public\\\gallery\\\herbs\\\4th.jpg';
$trainImage3 = 'c:\\\xampp\\\htdocs\\\identificare_api\\\public\\\gallery\\\herbs\\\1st.jpg';
$data = array
(
array(0, $queryImage),
array(1, $trainImage),
array(3, $trainImage1),
array(5, $trainImage2),
array(7, $trainImage3),
);
$count= count($data);
$a = 1;
$string = "";
foreach( $data as $d){
$string .= $d[0] . '-' . $d[1];
if($a < $count){
$string .= ",";
}
$a++;
}
$result = shell_exec("C:\Python27\python c:\xampp\htdocs\identificare_api\app\http\controllers\ORB\orb.py " . escapeshellarg($string));
echo $result;
}
Run Code Online (Sandbox Code Playgroud)
我的python脚本是一个ORB算法,它在将火车图像与查询图像进行比较后返回最小距离及其id.所以,这是我的python脚本:
import …Run Code Online (Sandbox Code Playgroud) 我刚刚使用了ORB的开源实现.
如何通过添加新模块来进一步实现ORB?
为了获得比使用ORB更好的结果,我能做些什么呢?
我正在考虑使用RANSAC来消除异常值并获得更好的结果.
我们在这一点上等待进一步实施ORB的想法.
有关圆形和三角形的Homography实现的任何想法?
我试图用ORB检测关键点一切正常,直到我切换到Opencv 2.4.9.
第一,似乎键的数量减少了,对于某些图像,没有检测到关键点:
这是我用两个版本编译的代码:(2.3.1和2.4.9)
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/features2d/features2d.hpp>
using namespace cv;
int main(int argc, char **argv){
Mat img = imread(argv[1]);
std::vector<KeyPoint> kp;
OrbFeatureDetector detector;
detector.detect(img, kp);
std::cout << "Found " << kp.size() << " Keypoints " << std::endl;
Mat out;
drawKeypoints(img, kp, out, Scalar::all(255));
imshow("Kpts", out);
waitKey(0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
结果:2.3.1:找到152个关键点

2.4.9:找到0个关键点

我还测试了一个不同的ORB构造函数,但我得到了相同的结果,没有KPts.与2.3.1默认的构造函数中相同的构造函数值:2.4.9 custom constr:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/features2d/features2d.hpp>
using namespace cv;
int main(int argc, char **argv){
Mat img = imread(argv[1]);
std::vector<KeyPoint> kp;
// default in …Run Code Online (Sandbox Code Playgroud) 如何使用 Python 在 BF MATCHER 中的最佳匹配上绘制边界框?