PixelSearch.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:pytomatic 作者: N0K0 项目源码 文件源码
def find_features_in_array_SIFT(self, sub_image, main_image, debug=False):
        # Initiate SIFT detector
        sift = SIFT_create()

        # find the keypoints and descriptors with SIFT
        kp1, des1 = sift.detectAndCompute(sub_image, None)
        kp2, des2 = sift.detectAndCompute(main_image, None)

        # BFMatcher with default params
        bf = cv2.BFMatcher()
        matches = bf.knnMatch(des1, des2, k=2)

        logging.debug("Found {} possible matches".format(len(matches)))

        ret_list = []
        good = []
        for m, n in matches:
            if m.distance < 0.75 * n.distance:
                good.append([m])

        good.sort(key=lambda x: x[0].distance)

        if debug:
            # cv2.drawMatchesKnn expects list of lists as matches.
            img3 = cv2.drawMatchesKnn(sub_image, kp1, main_image, kp2, good, flags=2, outImg=None,
                                      matchColor=(255, 255, 0))
            plt.imshow(img3), plt.show()

        ret_list = []
        for match in good:
            index = match[0].trainIdx
            point = kp2[index].pt
            ret_list.append((int(point[0]), int(point[1])))

        logging.debug("After filtering {}".format(len(good)))
        return ret_list
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号