__init__.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 import math
00005 
00006 import cv2
00007 import numpy as np
00008 import siftfastpy
00009 
00010 
00011 def get_sift_keypoints(img):
00012     """Get sift keypoints from image
00013     Parameters
00014     ----------
00015     img: array-like
00016         Input image of shape ``(M, N)`` from which we get sift keypoints
00017 
00018     Returns
00019     -------
00020     frames: numpy.ndarray
00021         each row has [col, row, orientation, scale] in this order
00022 
00023     desc: numpy.ndarray
00024         descriptors of each frame
00025     """
00026     if type(img) is not np.ndarray:
00027         img = np.array(img)
00028     if len(img.shape) != 2:
00029         raise ValueError('image should be 2d array: {}'.format(img.shape))
00030     siftimg = siftfastpy.Image(img.shape[1], img.shape[0])
00031     siftimg.SetData(img)
00032     frames, desc = siftfastpy.GetKeypoints(siftimg)
00033     return frames, desc
00034 
00035 
00036 def draw_sift_frames(img, frames):
00037     """
00038     Parameters
00039     ----------
00040     img: array-like
00041         Gray-scale image
00042     frames: numpy.ndarray
00043         each row has [col, row, orientation, scale] in this order
00044     """
00045     if len(img.shape) > 2:
00046         raise ValueError('input image should be gray-scale')
00047 
00048     keypoints = []
00049     for frame in frames:
00050         col, row, ori, scale = frame
00051         angle = ori / math.pi * 180
00052         kp = cv2.KeyPoint(x=col, y=row, _size=scale, _angle=angle)
00053         keypoints.append(kp)
00054     dst = cv2.drawKeypoints(img, keypoints,
00055                             flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
00056     return dst


imagesift
Author(s): Rosen Diankov (rdiankov@cs.cmu.edu), Kei Okada
autogenerated on Tue Jul 2 2019 19:40:45