当我在OpenCV中使用BRISK进行特征检测和描述时,我遇到了性能问题.
基本上我尝试匹配从这个图像得到的所有描述符:
我使用基于flann匹配器的LSH算法和BRISK进行特征检测和描述,从图像数据库中获取所有描述符.
我的图像数据库由242个图像组成.在该242个图像中,存在与在上述"复杂"图像查询中分别拍摄的每个对象相对应的三个图像.
以下是用于BRISK检测的参数(默认opencv参数):Treshold:30,Octaves:4,Pattern scale:1.0.
在使用最佳匹配技术进行flann匹配之后(图像查询中的每个描述符与数据库描述符集中最近的邻域相关联),我的算法输出按匹配百分比排序的数据库图像列表.以下是四个第一个结果:
我使用ORB作为特征检测和描述来比较这些结果.以下是使用的参数:特征数量:2000,比例因子:1.2,金字塔等级数量:8.
以下是我得到的结果:
正如您所看到的,ORB的结果要好得多.首先,在数据库中的每个图像上检测到更多的关键点,并且匹配的百分比对于好的对象明显更好.此外,良好对象的匹配百分比与错误对象的匹配百分比之间的差距更为显着.
我想知道为什么BRISK探测器检测到的关键点比ORB探测器少得多.我已经做了不同的测试来弄清楚如何用BRISK探测器探测更多的关键点(降低阈值,减少八度数).我确实可以检测到更多的关键点,但与ORB检测器的差异仍然非常重要.你知道为什么BRISK探测器有这样的行为吗?
我的OpenCV版本是2.4.8,但我根据这些声明尝试了2.4.4和2.4.9版本的BRISK检测部分:
http://code.opencv.org/issues/2491和BRISK特征检测器检测到零关键点而没有改进.
我还尝试将ORB检测器与BRISK描述相结合.匹配结果优于第一种方法(完全BRISK),但比第二种方法(完整ORB)更差:
请注意,在方法2和方法3中,每个图像上检测到的关键点数量并不相同.实际上,当我在测试图像上运行此代码时(此处为螺栓图像):
// BRISK parameters
int Threshl=30;
int Octaves=4;
float PatternScales=1.0f;
// ORB parameters
int nFeatures=2000;
float scaleFactor=1.2f;
int nLevels=8;
BRISK BRISKD(Threshl, Octaves, PatternScales);
ORB ORBD(nFeatures, scaleFactor, nLevels);
vector<KeyPoint> …Run Code Online (Sandbox Code Playgroud) 如本教程所述,我试图使用OpenCV ORB匹配两个图像。
这是我的代码:
import numpy as np
import cv2
import six
import pyparsing
import dateutil
from matplotlib import pyplot as plt
import timeit
import os
import sys
img1_path = 'img1.jpg'
img2_path = 'img2.jpg'
img1 = cv2.imread(img1_path,0) # queryImage
img2 = cv2.imread(img2_path,0) # trainImage
orb = cv2.ORB()
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
FLANN_INDEX_LSH = 6
index_params= dict(algorithm = FLANN_INDEX_LSH,
table_number = 6, # 12
key_size = 12, # 20
multi_probe_level = 1) #2
search_params = dict(checks …Run Code Online (Sandbox Code Playgroud) 在我之前的问题中,我了解到必须安装opencv-contrib以便将OpenCV Python与外部模块(如SIFT)一起使用.但是,在我的项目中,我想使用ORB或类似的东西.cv2.ORB()不起作用,也不起作用cv2.xfeatures2d.ORB_create()或任何其他命令的凝集.
据了解,OpenCV的Python API文档相当差.
如何使用ORB匹配OpenCV Python中的功能?
MWE:
#!/usr/bin/python2.7
import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('smallburger.jpg',0)
# Initiate STAR detector
orb = cv2.ORB()
# find the keypoints with ORB
kp = orb.detect(img,None)
# compute the descriptors with ORB
kp, des = orb.compute(img, kp)
# draw only keypoints location,not size and orientation
img2 = cv2.drawKeypoints(img,kp,color=(0,255,0), flags=0)
plt.imshow(img2),plt.show()
Run Code Online (Sandbox Code Playgroud)
CLI输出:
Traceback (most recent call last):
File "./mwe.py", …Run Code Online (Sandbox Code Playgroud) 如何在一个图像上找到一种类型的多个对象.我使用ORB特征查找器和强力匹配器(opencv = 3.2.0).
我的源代码:
import numpy as np
import cv2
from matplotlib import pyplot as plt
MIN_MATCH_COUNT = 10
img1 = cv2.imread('box.png', 0) # queryImage
img2 = cv2.imread('box1.png', 0) # trainImage
#img2 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
# Initiate ORB detector
#
orb = cv2.ORB_create(10000, 1.2, nlevels=9, edgeThreshold = 4)
#orb = cv2.ORB_create()
# find the keypoints and descriptors with SIFT
kp1, des1 = orb.detectAndCompute(img1, None)
kp2, des2 = orb.detectAndCompute(img2, None)
FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5) …Run Code Online (Sandbox Code Playgroud) 我的项目是使用 OpenCV 库识别 Android 上的叶子。我使用ORB检测来获取图像的关键点并使用ORB描述符来获取关键点的特征。这是我使用的代码:
bmp=BitmapFactory.decodeResource(getResources(),R.drawable.t1);
Utils.bitmapToMat(bmp, mat);
FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
detector.detect(mat, keypoints);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
extractor.compute(mat, keypoints, features);
Run Code Online (Sandbox Code Playgroud)
来源:http : //answers.opencv.org/question/6260/orb-features/
但是每次我输入相同的图像,该图像的关键点总是不同的。如果总是不同,我可以将关键点的特征保存到数据库吗?或者我应该保存图像以保存特征数据?如果可以保存到数据库,我该怎么做??
我想使用图像中先前检测到的 ORB 特征位置来提取另一幅图像中的 ORB 描述符,使用较早确定的位置,从而绕过检测器。
我似乎无法获得检测到的特征的深层副本进行处理,然后再传回以生成新的描述符。
f1关键点为im_y图像作品生成描述符代码:
from matplotlib import pyplot as plt
import copy as cp
import cv2
im_x = cv2.imread('stinkbug1.png', 0)
im_y = cv2.imread('stinkbug2.png', 0)
orb = cv2.ORB()
# Keypoint detection in first image
f1 = orb.detect(im_x, None)
f1, d1 = orb.compute(im_x, f1)
# Make a copy of the orginal key points
f2 = cp.deepcopy(f1)
# Magic processing here
# …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用FLANN实现ORB,我已经阅读了文档并且它说当使用ORB和FLANN时我必须使用:
index_params= dict(algorithm = FLANN_INDEX_LSH,
table_number = 6, # 12
key_size = 12, # 20
multi_probe_level = 1) #2
Run Code Online (Sandbox Code Playgroud)
我的代码
def useFLANN(img1, img2, kp1, kp2, des1, des2, setDraw, type):
# Fast Library for Approximate Nearest Neighbors
MIN_MATCH_COUNT = 10
FLANN_INDEX_KDTREE = 0
if type == True:
# Detect with ORB
index_params= dict(algorithm = FLANN_INDEX_LSH,
table_number = 6, # 12
key_size = 12, # 20
multi_probe_level = 1) #2
else:
# Detect with Others such as SURF, SIFT
index_params = dict(algorithm …Run Code Online (Sandbox Code Playgroud) 我正在使用OpenCV 3.2
我试图使用FLANN以比蛮力更快的方式匹配功能描述符.
// Ratio to the second neighbor to consider a good match.
#define RATIO 0.75
void matchFeatures(const cv::Mat &query, const cv::Mat &target,
std::vector<cv::DMatch> &goodMatches) {
std::vector<std::vector<cv::DMatch>> matches;
cv::Ptr<cv::FlannBasedMatcher> matcher = cv::FlannBasedMatcher::create();
// Find 2 best matches for each descriptor to make later the second neighbor test.
matcher->knnMatch(query, target, matches, 2);
// Second neighbor ratio test.
for (unsigned int i = 0; i < matches.size(); ++i) {
if (matches[i][0].distance < matches[i][1].distance * RATIO)
goodMatches.push_back(matches[i][0]);
}
}
Run Code Online (Sandbox Code Playgroud)
此代码使用SURF和SIFT描述符,但不使用ORB.
OpenCV Error: …Run Code Online (Sandbox Code Playgroud) ORB 演示代码位于https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_feature2d/py_orb/py_orb.html
import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('simple.jpg',0)
# Initiate STAR detector
orb = cv2.ORB()
# find the keypoints with ORB
kp = orb.detect(img,None)
# compute the descriptors with ORB
kp, des = orb.compute(img, kp)
# draw only keypoints location,not size and orientation
img2 = cv2.drawKeypoints(img,kp,color=(0,255,0), flags=0)
plt.imshow(img2),plt.show()
Run Code Online (Sandbox Code Playgroud)
在kp = orb.detect(img,None)
[WinError 10054] An existing connection was forcibly closed by the remote hostcv2.error: Unknown C++ exception …我有以下使用 ORB 进行图像匹配的代码:
import numpy as np
import cv2
from matplotlib import pyplot as plt
img1 = cv2.imread('C:\\IRRNEW\\models\\research\\object_detection\\Scanner\\IMG_Hello.jpg',0) # queryImage
img2 = cv2.imread('C:\\IRRNEW\\models\\research\\object_detection\\Image.jpg',0) # trainImage
#orb = cv2.ORB_create()
orb = cv2.ORB_create(nfeatures=10000, scoreType=cv2.ORB_FAST_SCORE)
# find the keypoints with ORB
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = bf.match(des1,des2)
matches = sorted(matches, key = lambda x:x.distance)
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[::], None,flags=2)
a=len(matches)
print(a)
b=len(des)
print(b)
plt.imshow(img3),plt.show()
Run Code Online (Sandbox Code Playgroud)
以前这段代码能够运行并显示结果,但现在突然给我这个错误:
Traceback (most recent call last):
File "C:\Users\user\Desktop\h.py", line 13, in …Run Code Online (Sandbox Code Playgroud)