本文整理汇总了Python中cv2.SIFT属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.SIFT属性的具体用法?Python cv2.SIFT怎么用?Python cv2.SIFT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cv2
的用法示例。
在下文中一共展示了cv2.SIFT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_detector
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import SIFT [as 别名]
def init_detector(self):
"""Init keypoint detector object."""
# BRIEF is a feature descriptor, recommand CenSurE as a fast detector:
if check_cv_version_is_new():
# OpenCV3/4, sift is in contrib module, you need to compile it seperately.
try:
self.detector = cv2.xfeatures2d.SIFT_create(edgeThreshold=10)
except:
import traceback
traceback.print_exc()
raise NoModuleError("There is no %s module in your OpenCV environment, need contribmodule!" % self.METHOD_NAME)
else:
# OpenCV2.x
self.detector = cv2.SIFT(edgeThreshold=10)
# # create FlnnMatcher object:
self.matcher = cv2.FlannBasedMatcher({'algorithm': self.FLANN_INDEX_KDTREE, 'trees': 5}, dict(checks=50))
示例2: init_feature
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import SIFT [as 别名]
def init_feature(name):
chunks = name.split('-')
if chunks[0] == 'sift':
detector = cv2.SIFT()
norm = cv2.NORM_L2
elif chunks[0] == 'surf':
detector = cv2.SURF(800)
norm = cv2.NORM_L2
elif chunks[0] == 'orb':
detector = cv2.ORB(400)
norm = cv2.NORM_HAMMING
else:
return None, None
if 'flann' in chunks:
if norm == cv2.NORM_L2:
flann_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
else:
flann_params= dict(algorithm = FLANN_INDEX_LSH,
table_number = 6, # 12
key_size = 12, # 20
multi_probe_level = 1) #2
matcher = cv2.FlannBasedMatcher(flann_params, {}) # bug : need to pass empty dict (#1329)
else:
matcher = cv2.BFMatcher(norm)
return detector, matcher
示例3: feature_similarity
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import SIFT [as 别名]
def feature_similarity(image_1,image_2,threshold=0.7):
"""SIFT Feature based image similarity
@param image_1: np.array(the first input image)
@param image_2: np.array(the second input image)
@param threshold: float(the lower's threshold)
@return similarity: float(range from [0,1], the bigger the more similar)
@return good_match_num; int(the number of good match point pairs)
"""
kp1, des1 = _sift_extract(image_1)
kp2, des2 = _sift_extract(image_2)
if len(kp1) <= len(kp2):
num = len(kp1)
else:
num = len(kp2)
if num <= 0:
similarity, good_match_num = 0.0, 0.0
else:
good_match, default = _searchAndmatch(des1, des2, threshold)
good_match_num = float(len(good_match))
similarity = good_match_num/num
return similarity, good_match_num
示例4: init_feature
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import SIFT [as 别名]
def init_feature(name):
chunks = name.split('-')
if chunks[0] == 'sift':
detector = cv2.SIFT()
norm = cv2.NORM_L2
elif chunks[0] == 'surf':
detector = cv2.SURF(400)
norm = cv2.NORM_L2
elif chunks[0] == 'orb':
detector = cv2.ORB(400)
norm = cv2.NORM_HAMMING
else:
return None, None
if 'flann' in chunks:
if norm == cv2.NORM_L2:
flann_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
else:
flann_params= dict(algorithm = FLANN_INDEX_LSH,
table_number = 6, # 12
key_size = 12, # 20
multi_probe_level = 1) #2
matcher = cv2.FlannBasedMatcher(flann_params, {}) # bug : need to pass empty dict (#1329)
else:
matcher = cv2.BFMatcher(norm)
return detector, matcher
示例5: find_sift
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import SIFT [as 别名]
def find_sift(im_source, im_search, min_match_count=4):
'''
SIFT特征点匹配
'''
res = find_all_sift(im_source, im_search, min_match_count, maxcnt=1)
if not res:
return None
return res[0]
示例6: _init_sift
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import SIFT [as 别名]
def _init_sift():
"""Make sure that there is SIFT module in OpenCV."""
if cv2.__version__.startswith("3."):
# OpenCV3.x, sift is in contrib module, you need to compile it seperately.
try:
sift = cv2.xfeatures2d.SIFT_create(edgeThreshold=10)
except:
print("to use SIFT, you should build contrib with opencv3.0")
raise NoSIFTModuleError("There is no SIFT module in your OpenCV environment !")
else:
# OpenCV2.x, just use it.
sift = cv2.SIFT(edgeThreshold=10)
return sift
示例7: _sift_instance
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import SIFT [as 别名]
def _sift_instance(self, edge_threshold=100):
if hasattr(cv2, 'SIFT'):
return cv2.SIFT(edgeThreshold=edge_threshold)
return cv2.xfeatures2d.SIFT_create(edgeThreshold=edge_threshold)
示例8: find_sift
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import SIFT [as 别名]
def find_sift(self, im_source, im_search, min_match_count=4):
'''
SIFT特征点匹配
'''
res = self.find_all_sift(im_source, im_search, min_match_count, maxcnt=1)
if not res:
return None
return res[0]
示例9: _reremove
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import SIFT [as 别名]
def _reremove(list):
checked = []
for e in list:
if e not in checked: checked.append(e)
return checked
#SIFT extraction
示例10: _sift_extract
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import SIFT [as 别名]
def _sift_extract(image):
sift = cv2.SIFT()
keypoints, descriptors = sift.detectAndCompute(image, None)
return keypoints, descriptors
#search and match keypoint_pair
示例11: _re_cluster_center
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import SIFT [as 别名]
def _re_cluster_center(image, centers, match_points,
hori_distance, veti_distance, threshold):
"""refine center
@param image: np.array(input target image)
@param match_points: list(contains points that are matched)
@param hori_distance: int(restrict the horizontal distance between points)
@param veti_distance: int(restrict the vetical distance between points)
@param threshold: int(define the least points belonging to one center)
@return new_centers: list(they are sorted by the ascending of y coordinate)
"""
re_centers = []
re_match_points = _reremove(match_points)
for i in range(len(centers)):
sum_x, sum_y, k = 0, 0, 0
top_left_x = centers[i][0]-int(hori_distance/2)
top_left_y = centers[i][1]-int(veti_distance/2)
bottom_right_x = centers[i][0] + int(hori_distance/2)
bottom_right_y = centers[i][1] + int(veti_distance/2)
for j in range(len(re_match_points)):
'''选择在中心点附近一定区域内的关键点'''
if (abs(centers[i][0]-re_match_points[j][0])<int(hori_distance/2) and
abs(centers[i][1]-re_match_points[j][1])<int(veti_distance/2) and
0 < top_left_x and 0 < top_left_y and
bottom_right_x<image.shape[1] and bottom_right_y<image.shape[0]):
sum_x = sum_x + re_match_points[j][0]
sum_y = sum_y + re_match_points[j][1]
k = k + 1
if threshold <= k and 0 < k:
[x, y] = [int(float(sum_x)/k), int(float(sum_y)/k)]
re_centers.append([x, y])
new_centers = _sort_point_list(re_centers)
return new_centers
#SIFT extraction
示例12: _homography
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import SIFT [as 别名]
def _homography(src_pts,dst_pts,template_width,template_height,match_point=None):
row,col,dim = dst_pts.shape
if match_point:
for i in range(row):
match_point.append([int(dst_pts[i][0][0]),int(dst_pts[i][0][1])])
M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0)
pts = np.float32([[0, 0], [0, template_height - 1],
[template_width - 1, template_height - 1],
[template_width - 1, 0]]).reshape(-1, 1, 2)
#找到一个变换矩阵,从查询图映射到检测图片
dst = cv2.perspectiveTransform(pts, M)
return dst
#SIFT + Homography
示例13: hist_similarity
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import SIFT [as 别名]
def hist_similarity(image_1, image_2):
"""color hist based image similarity
@param image_1: np.array(the first input image)
@param image_2: np.array(the second input image)
@return similarity: float(range from [0,1], the bigger the more similar)
"""
if image_1.ndim == 2 and image_2.ndim == 2:
hist_1 = cv2.calcHist([image_1], [0], None, [256], [0.0, 255.0])
hist_2 = cv2.calcHist([image_2], [0], None, [256], [0.0, 255.0])
similarity = cv2.compareHist(hist_1, hist_2, cv2.cv.CV_COMP_CORREL)
elif image_1.ndim == 3 and image_2.ndim == 3:
"""R,G,B split"""
b_1, g_1, r_1 = cv2.split(image_1)
b_2, g_2, r_2 = cv2.split(image_2)
hist_b_1 = cv2.calcHist([b_1], [0], None, [256], [0.0, 255.0])
hist_g_1 = cv2.calcHist([g_1], [0], None, [256], [0.0, 255.0])
hist_r_1 = cv2.calcHist([r_1], [0], None, [256], [0.0, 255.0])
hist_b_2 = cv2.calcHist([b_2], [0], None, [256], [0.0, 255.0])
hist_g_2 = cv2.calcHist([g_2], [0], None, [256], [0.0, 255.0])
hist_r_2 = cv2.calcHist([r_2], [0], None, [256], [0.0, 255.0])
similarity_b = cv2.compareHist(hist_b_1,hist_b_2,cv2.cv.CV_COMP_CORREL)
similarity_g = cv2.compareHist(hist_g_1,hist_g_2,cv2.cv.CV_COMP_CORREL)
similarity_r = cv2.compareHist(hist_r_1,hist_r_2,cv2.cv.CV_COMP_CORREL)
sum_bgr = similarity_b + similarity_g + similarity_r
similarity = sum_bgr/3.
else:
gray_1 = cv2.cvtColor(image_1,cv2.cv.CV_RGB2GRAY)
gray_2 = cv2.cvtColor(image_2,cv2.cv.CV_RGB2GRAY)
hist_1 = cv2.calcHist([gray_1], [0], None, [256], [0.0, 255.0])
hist_2 = cv2.calcHist([gray_2], [0], None, [256], [0.0, 255.0])
similarity = cv2.compareHist(hist_1, hist_2, cv2.cv.CV_COMP_CORREL)
return similarity
#SIFT based similarity
示例14: _sift_instance
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import SIFT [as 别名]
def _sift_instance(edge_threshold=100):
if hasattr(cv2, 'SIFT'):
return cv2.SIFT(edgeThreshold=edge_threshold)
return cv2.xfeatures2d.SIFT_create(edgeThreshold=edge_threshold)
示例15: main
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import SIFT [as 别名]
def main():
print(cv2.IMREAD_COLOR)
print(cv2.IMREAD_GRAYSCALE)
print(cv2.IMREAD_UNCHANGED)
imsrc = imread('testdata/1s.png')
imsch = imread('testdata/1t.png')
print(brightness(imsrc))
print(brightness(imsch))
pt = find(imsrc, imsch)
#mark_point(imsrc, pt)
#show(imsrc)
imsrc = imread('testdata/2s.png')
imsch = imread('testdata/2t.png')
result = find_all_template(imsrc, imsch)
print(result)
pts = []
for match in result:
pt = match["result"]
#mark_point(imsrc, pt)
pts.append(pt)
# pts.sort()
#show(imsrc)
# print pts
# print sorted(pts, key=lambda p: p[0])
imsrc = imread('yl/bg_half.png')
imsch = imread('yl/q_small.png')
print(result)
print('SIFT count=', sift_count(imsch))
print(find_sift(imsrc, imsch))
print(find_all_sift(imsrc, imsch))
print(find_all_template(imsrc, imsch))
print(find_all(imsrc, imsch))