Python cv2.FeatureDetector_create() Examples

The following are 10 code examples for showing how to use cv2.FeatureDetector_create(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module cv2 , or try the search function .

Example 1
Project: Airtest   Author: AirtestProject   File: keypoint_matching_contrib.py    License: Apache License 2.0 6 votes vote down vote up
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, star/brief is in contrib module, you need to compile it seperately.
            try:
                self.star_detector = cv2.xfeatures2d.StarDetector_create()
                self.brief_extractor = cv2.xfeatures2d.BriefDescriptorExtractor_create()
            except:
                import traceback
                traceback.print_exc()
                print("to use %s, you should build contrib with opencv3.0" % self.METHOD_NAME)
                raise NoModuleError("There is no %s module in your OpenCV environment !" % self.METHOD_NAME)
        else:
            # OpenCV2.x
            self.star_detector = cv2.FeatureDetector_create("STAR")
            self.brief_extractor = cv2.DescriptorExtractor_create("BRIEF")

        # create BFMatcher object:
        self.matcher = cv2.BFMatcher(cv2.NORM_L1)  # cv2.NORM_L1 cv2.NORM_L2 cv2.NORM_HAMMING(not useable) 
Example 2
Project: dual-fisheye-video-stitching   Author: cynricfu   File: stitcher.py    License: MIT License 6 votes vote down vote up
def detectAndDescribe(self, image):
        # check to see if we are using OpenCV 3.X
        if int(cv2.__version__[0]) >= 3:
            # detect and extract features from the image
            descriptor = cv2.xfeatures2d.SIFT_create()
            (kps, features) = descriptor.detectAndCompute(image, None)

        # otherwise, we are using OpenCV 2.4.X
        else:
            # convert the image to grayscale
            gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

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

            # extract features from the image
            extractor = cv2.DescriptorExtractor_create("SIFT")
            (kps, features) = extractor.compute(gray, 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) 
Example 3
Project: imutils   Author: jrosebr1   File: factories.py    License: MIT License 6 votes vote down vote up
def FeatureDetector_create(detector, *args, **kw_args):
        """

        :param detector: string of the type of keypoint detector to return
        :param args: positional arguments for detector
        :param kw_args: keyword arguments for detector
        :return: the key point detector object
        """
        try:
            detr = _DETECTOR_FACTORY[detector.upper()]
        except KeyError:
            if detector.upper() in _CONTRIB_FUNCS:
                msg = "OpenCV needs to be compiled with opencv_contrib to support {}".format(detector)
                raise AttributeError(msg)
            raise AttributeError("{} not a supported detector".format(detector))

        return detr(*args, **kw_args) 
Example 4
def __init__ (self):
		"""
			PUBLIC: Constructor
			-------------------
			board_image: BoardImage object, the first frame
		"""
		#=====[ Step 1: set up feature extractors	]=====
		'''
		self.corner_detector = cv2.FeatureDetector_create ('HARRIS')
		'''
		self.sift_descriptor = cv2.xfeatures2d.SIFT_create()








	####################################################################################################
	##############################[ --- FIND BOARD CORNER CORRESPONDENCES --- ]#########################
	#################################################################################################### 
Example 5
def __init__ (self):
		"""
			PUBLIC: Constructor
			-------------------
			board_image: BoardImage object, the first frame
		"""
		#=====[ Step 1: set up feature extractors	]=====
		self.corner_detector = cv2.FeatureDetector_create ('HARRIS')
		self.sift_descriptor = cv2.DescriptorExtractor_create('SIFT')










	####################################################################################################
	##############################[ --- FIND BOARD CORNER CORRESPONDENCES --- ]#########################
	#################################################################################################### 
Example 6
Project: imutils   Author: jrosebr1   File: factories.py    License: MIT License 5 votes vote down vote up
def FeatureDetector_create(method):
        method = method.upper()
        if method == "DENSE":
            return DENSE()
        elif method == "GFTT":
            return GFTT()
        elif method == "HARRIS":
            return HARRIS()
        return cv2.FeatureDetector_create(method) 
Example 7
def get_harris_corners (image):
	"""
		Function: get_harris_corners
		----------------------------
		given an image, returns a list of cv2.KeyPoints representing
		the harris corners
	"""
	corner_detector = cv2.FeatureDetector_create ('HARRIS')
	return corner_detector.detect (image) 
Example 8
def get_harris_corners (image):
	"""
		Function: get_harris_corners
		----------------------------
		given an image, returns a list of cv2.KeyPoints representing
		the harris corners
	"""
	corner_detector = cv2.FeatureDetector_create ('HARRIS')
	return corner_detector.detect (image) 
Example 9
Project: omgh   Author: yassersouri   File: extractor.py    License: MIT License 5 votes vote down vote up
def __init__(self, storage):
        super(SIFT_SIFT_Extractor, self).__init__(storage)
        self.STORAGE_SUB_NAME = 'sift_sift'
        self.sub_folder = self.storage.get_sub_folder(
            self.STORAGE_SUPER_NAME, self.STORAGE_SUB_NAME)
        self.storage.ensure_dir(self.sub_folder)

        self._keypoint_detector = cv2.FeatureDetector_create("SIFT")
        self._keypoint_extractor = cv2.DescriptorExtractor_create("SIFT") 
Example 10
Project: DoNotSnap   Author: AVGInnovationLabs   File: classify.py    License: GNU General Public License v3.0 4 votes vote down vote up
def main(image_file):
    image = Image.open(image_file)
    if image is None:
        print 'Could not load image "%s"' % sys.argv[1]
        return

    image = np.array(image.convert('RGB'), dtype=np.uint8)
    image = image[:, :, ::-1].copy()

    winSize = (200, 200)
    stepSize = 32

    roi = extractRoi(image, winSize, stepSize)
    weight_map, mask_scale = next(roi)

    samples = [(rect, scale, cv2.cvtColor(window, cv2.COLOR_BGR2GRAY))
               for rect, scale, window in roi]

    X_test = [window for rect, scale, window in samples]
    coords = [(rect, scale) for rect, scale, window in samples]

    extractor = cv2.FeatureDetector_create('SURF')
    detector = cv2.DescriptorExtractor_create('SURF')

    affine = AffineInvariant(extractor, detector)

    saved = pickle.load(open('classifier.pkl', 'rb'))

    feature_transform = saved['pipe']
    model = saved['model']

    print 'Extracting Affine transform invariant features'
    affine_invariant_features = affine.transform(X_test)
    print 'Matching features with template'
    features = feature_transform.transform(affine_invariant_features)

    rects = classify(model, features, coords, weight_map, mask_scale)
    for (left, top, right, bottom) in non_max_suppression_fast(rects, 0.4):
        cv2.rectangle(image, (left, top), (right, bottom), (0, 0, 0), 10)
        cv2.rectangle(image, (left, top), (right, bottom), (32, 32, 255), 5)

    plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
    plt.show()