當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.SIFT屬性代碼示例

本文整理匯總了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)) 
開發者ID:AirtestProject,項目名稱:Airtest,代碼行數:19,代碼來源:keypoint_matching_contrib.py

示例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 
開發者ID:NetEase,項目名稱:airtest,代碼行數:27,代碼來源:findobj.py

示例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 
開發者ID:NetEase,項目名稱:airtest,代碼行數:24,代碼來源:auto.py

示例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 
開發者ID:UASLab,項目名稱:ImageAnalysis,代碼行數:27,代碼來源:find_obj.py

示例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] 
開發者ID:NetEaseGame,項目名稱:aircv,代碼行數:10,代碼來源:__init__.py

示例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 
開發者ID:AirtestProject,項目名稱:Airtest,代碼行數:16,代碼來源:sift.py

示例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) 
開發者ID:openatx,項目名稱:uiautomator2,代碼行數:6,代碼來源:__init__.py

示例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] 
開發者ID:openatx,項目名稱:uiautomator2,代碼行數:10,代碼來源:__init__.py

示例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 
開發者ID:NetEase,項目名稱:airtest,代碼行數:9,代碼來源:image_SIFT.py

示例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 
開發者ID:NetEase,項目名稱:airtest,代碼行數:8,代碼來源:image_SIFT.py

示例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 
開發者ID:NetEase,項目名稱:airtest,代碼行數:37,代碼來源:auto.py

示例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 
開發者ID:NetEase,項目名稱:airtest,代碼行數:16,代碼來源:auto.py

示例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 
開發者ID:NetEase,項目名稱:airtest,代碼行數:37,代碼來源:auto.py

示例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) 
開發者ID:NetEaseGame,項目名稱:aircv,代碼行數:6,代碼來源:__init__.py

示例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)) 
開發者ID:NetEaseGame,項目名稱:aircv,代碼行數:36,代碼來源:__init__.py


注:本文中的cv2.SIFT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。