コード例 #1
0
ファイル: test.py プロジェクト: thugbobby/Python_public
def matchImages(original, image_to_compare, useFlann=False):

    if useRootSIFT:
        # extract RootSIFT descriptors
        #print('Using RootSIFT')
        kps = None
        rs = RootSIFT()
        kp_1, desc_1 = rs.compute(original, kps)
        kp_2, desc_2 = rs.compute(image_to_compare, kps)
    else:
        sift = cv2.xfeatures2d.SIFT_create()
        kp_1, desc_1 = sift.detectAndCompute(original, None)
        kp_2, desc_2 = sift.detectAndCompute(image_to_compare, None)

    if useFlann:
        FLANN_INDEX_KDTREE = 0
        index_params = dict(algorithm=FLANN_INDEX_KDTREE, trees=5)
        search_params = dict(checks=50)
        print('Using Flann Matcher')
        matcher = cv2.FlannBasedMatcher(index_params, search_params)
    else:
        print('Using Brute Force Matcher')
        matcher = cv2.DescriptorMatcher_create("BruteForce")

    matches = matcher.knnMatch(desc_1, desc_2, k=2)

    good_points = []
    for m, n in matches:
        if m.distance < LRatio * n.distance:
            good_points.append(m)
    print(len(good_points))
    result = cv2.drawMatches(original, kp_1, image_to_compare, kp_2,
                             good_points, None)
    #  cv2.imshow("result", cv2.resize(result,(800,600)))
    return (good_points, result)
コード例 #2
0
ファイル: Matcher.py プロジェクト: thugbobby/Python_public
    def detectAndDescribe(self, image, useRootSIFT=False):
        # convert the image to grayscale
        #		gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

        # check to see if we are using OpenCV 3.X
        if self.isv3:
            if useRootSIFT:
                # extract RootSIFT descriptors
                #				print('Using RootSIFT')
                kps = None
                rs = RootSIFT()
                (kps, features) = rs.compute(image, kps)
            else:
                # detect and extract features from the image
                descriptor = cv2.xfeatures2d.SIFT_create()
                #				descriptor = cv2.xfeatures2d.SURF_create()
                #				descriptor = cv2.ORB_create()
                (kps, features) = descriptor.detectAndCompute(image, None)

        # otherwise, we are using OpenCV 2.4.X
        else:
            # detect keypoints in the image
            detector = cv2.FeatureDetector_create("SIFT")
            kps = detector.detect(image)

            # extract features from the image
            extractor = cv2.DescriptorExtractor_create("SIFT")
            (kps, features) = extractor.compute(image, kps)

        # convert the keypoints from KeyPoint objects to NumPy
        # arrays
        kps = np.float32([kp.pt for kp in kps])

        # return a tuple of keypoints and features
        return (kps, features)
コード例 #3
0
ファイル: doan.py プロジェクト: nguyendu393/DoANIR
def getRootSIFT(gray):
    sift = cv2.xfeatures2d.SIFT_create()
    kp, des = sift.detectAndCompute(gray, None)
    # extract RootSIFT descriptors
    rs = RootSIFT()
    kp, des = rs.compute(gray, kp)
    return kp, des
コード例 #4
0
def init_detect_extract(params):
    '''
    Initialize detector and extractor from parameters
    '''
    if params['descriptor_type'] == 'RootSIFT':

        extractor = RootSIFT()
    else:

        extractor = cv2.DescriptorExtractor_create(params['descriptor_type'])

    detector = cv2.FeatureDetector_create(params['keypoint_type'])

    return detector, extractor
コード例 #5
0
from __future__ import print_function
from rootsift import RootSIFT
import argparse
import cv2
import imutils

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(ap.parse_args())

# load the input image, convert it to grayscale
image = cv2.imread(args["image"])
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# extract local invariant descriptors
extractor = RootSIFT()
(kps, descs) = extractor.compute(gray, None)

# show the shape of the keypoints and local invariant descriptors array
print("[INFO] # of keypoints detected: {}".format(len(kps)))
print("[INFO] feature vector shape: {}".format(descs.shape))
コード例 #6
0
ファイル: driver.py プロジェクト: Paladugu33/MY_PRO
# USAGE
# python driver.py

# import the necessary packages
from rootsift import RootSIFT
import cv2

# load the image we are going to extract descriptors from and convert
# it to grayscale
image = cv2.imread("example.png")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# detect Difference of Gaussian keypoints in the image
detector = cv2.FeatureDetector_create("SIFT")
kps = detector.detect(gray)

# extract normal SIFT descriptors
extractor = cv2.DescriptorExtractor_create("SIFT")
(kps, descs) = extractor.compute(gray, kps)
print("SIFT: kps=%d, descriptors=%s " % (len(kps), descs.shape))

# extract RootSIFT descriptors
rs = RootSIFT()
(kps, descs) = rs.compute(gray, kps)
print("RootSIFT: kps=%d, descriptors=%s " % (len(kps), descs.shape))