-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from drhoffma/master
Added feature matcher factory. Added Dense, GFTT, Harris, and RootSIF…
- Loading branch information
Showing
8 changed files
with
124 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
from .helpers import corners_to_keypoints | ||
from .factories import FeatureDetector_create | ||
from .factories import DescriptorExtractor_create | ||
from .gftt import GFTT | ||
from .factories import DescriptorMatcher_create | ||
from .dense import DENSE | ||
from .gftt import GFTT | ||
from .harris import HARRIS | ||
from .rootsift import RootSIFT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import cv2 | ||
|
||
class DENSE: | ||
def __init__(self, step=6, radius=.5): | ||
self.step = step | ||
self.radius = radius | ||
|
||
def detect(self, img): | ||
# initialize our list of keypoints | ||
kps = [] | ||
|
||
# loop over the height and with of the image, taking a `step` | ||
# in each direction | ||
for x in range(0, img.shape[1], self.step): | ||
for y in range(0, img.shape[0], self.step): | ||
# create a keypoint and add it to the keypoints list | ||
kps.append(cv2.KeyPoint(x, y, self.radius)) | ||
|
||
# return the dense keypoints | ||
return kps | ||
|
||
def setInt(self, var, val): | ||
if var == "initXyStep": | ||
self.step = val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import cv2 | ||
import numpy as np | ||
from .helpers import corners_to_keypoints | ||
|
||
|
||
class HARRIS: | ||
def __init__(self, blockSize=2, apertureSize=3, k=0.1, T=0.02): | ||
self.blockSize = blockSize | ||
self.apertureSize = apertureSize | ||
self.k = k | ||
self.T = T | ||
|
||
def detect(self, img): | ||
# convert our input image to a floating point data type and then | ||
# compute the Harris corner matrix | ||
gray = np.float32(img) | ||
H = cv2.cornerHarris(gray, self.blockSize, self.apertureSize, self.k) | ||
|
||
# for every (x, y)-coordinate where the Harris value is above the | ||
# threshold, create a keypoint (the Harris detector returns | ||
# keypoint size a 3-pixel radius) | ||
kps = np.argwhere(H > self.T * H.max()) | ||
kps = [cv2.KeyPoint(pt[1], pt[0], 3) for pt in kps] | ||
|
||
# return the Harris keypoints | ||
return kps |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# import the necessary packages | ||
import numpy as np | ||
import cv2 | ||
from ..convenience import is_cv2 | ||
from . import factories | ||
|
||
class RootSIFT: | ||
def __init__(self): | ||
# initialize the SIFT feature extractor | ||
self.extractor = factories.DescriptorExtractor_create("SIFT") | ||
|
||
def compute(self, image, kps, eps=1e-7): | ||
# compute SIFT descriptors for OpenCV 2.4 | ||
if is_cv2: | ||
(kps, descs) = self.extractor.compute(image, kps) | ||
|
||
# otherwise, computer SIFT descriptors for OpenCV 3+ | ||
else: | ||
(kps, descs) = self.extractor.detectAndCompute(image, None) | ||
|
||
# if there are no keypoints or descriptors, return an empty tuple | ||
if len(kps) == 0: | ||
return ([], None) | ||
|
||
# apply the Hellinger kernel by first L1-normalizing and taking the | ||
# square-root | ||
descs /= (descs.sum(axis=1, keepdims=True) + eps) | ||
descs = np.sqrt(descs) | ||
|
||
# return a tuple of the keypoints and descriptors | ||
return (kps, descs) |