__init__.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 import math
5 
6 import cv2
7 import numpy as np
8 import siftfastpy
9 
10 
12  """Get sift keypoints from image
13  Parameters
14  ----------
15  img: array-like
16  Input image of shape ``(M, N)`` from which we get sift keypoints
17 
18  Returns
19  -------
20  frames: numpy.ndarray
21  each row has [col, row, orientation, scale] in this order
22 
23  desc: numpy.ndarray
24  descriptors of each frame
25  """
26  if type(img) is not np.ndarray:
27  img = np.array(img)
28  if len(img.shape) != 2:
29  raise ValueError('image should be 2d array: {}'.format(img.shape))
30  siftimg = siftfastpy.Image(img.shape[1], img.shape[0])
31  siftimg.SetData(img)
32  frames, desc = siftfastpy.GetKeypoints(siftimg)
33  return frames, desc
34 
35 
36 def draw_sift_frames(img, frames):
37  """
38  Parameters
39  ----------
40  img: array-like
41  Gray-scale image
42  frames: numpy.ndarray
43  each row has [col, row, orientation, scale] in this order
44  """
45  if len(img.shape) > 2:
46  raise ValueError('input image should be gray-scale')
47 
48  keypoints = []
49  for frame in frames:
50  col, row, ori, scale = frame
51  angle = ori / math.pi * 180
52  kp = cv2.KeyPoint(x=col, y=row, _size=scale, _angle=angle)
53  keypoints.append(kp)
54  dst = cv2.drawKeypoints(img, keypoints,
55  flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
56  return dst
def draw_sift_frames(img, frames)
Definition: __init__.py:36
def get_sift_keypoints(img)
Definition: __init__.py:11


imagesift
Author(s): Rosen Diankov (rdiankov@cs.cmu.edu), Kei Okada
autogenerated on Mon May 3 2021 03:03:10