-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
123 additions
and
16 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Python | ||
|
||
To run this code set parameters in run_demo.sh and execute `./run_demo.sh` from your terminal. | ||
|
||
We have tested with Python 2.7.6 and OpenCV 2.4.8 |
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,36 @@ | ||
#!/usr/bin/env python | ||
|
||
import argparse | ||
import cv2 | ||
import numpy | ||
from random import shuffle | ||
from ssc import * | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--image_path', type=str, default="../Images/test.png") | ||
parser.add_argument('--num_ret_points', type=int, default=10) | ||
parser.add_argument('--tolerance', type=float, default=0.1) | ||
args = parser.parse_args() | ||
|
||
img = cv2.imread(args.image_path) | ||
cv2.imshow('Input Image', img) | ||
cv2.waitKey(0) | ||
|
||
fast = cv2.FastFeatureDetector() | ||
keypoints = fast.detect(img, None) | ||
img2 = cv2.drawKeypoints(img, keypoints, color=(255,0,0)) | ||
cv2.imshow('Detected FAST keypoints', img2) | ||
cv2.waitKey(0) | ||
|
||
# keypoints should be sorted by strength in descending order before feeding to SSC to work correctly | ||
shuffle(keypoints) # simulating sorting by score with random shuffle | ||
|
||
selected_keypoints = SSC(keypoints, args.num_ret_points, args.tolerance, img.shape[1], img.shape[0]) | ||
|
||
img3 = cv2.drawKeypoints(img, selected_keypoints, color=(255,0,0)) | ||
cv2.imshow('Selected keypoints', img3) | ||
cv2.waitKey(0) | ||
|
||
if __name__ == '__main__': | ||
main() |
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,4 @@ | ||
python demo.py \ | ||
--image_path='../Images/test.png' \ | ||
--num_ret_points=750 \ | ||
--tolerance=0.1 \ |
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,62 @@ | ||
import math | ||
|
||
def SSC(keypoints, num_ret_points, tolerance, cols, rows): | ||
exp1 = rows + cols + 2*num_ret_points | ||
exp2 = 4*cols + 4*num_ret_points + 4*rows*num_ret_points + rows*rows + cols*cols - 2*rows*cols + 4*rows*cols*num_ret_points | ||
exp3 = math.sqrt(exp2) | ||
exp4 = (2*(num_ret_points - 1)) | ||
|
||
sol1 = -round(float(exp1+exp3)/exp4) # first solution | ||
sol2 = -round(float(exp1-exp3)/exp4) # second solution | ||
|
||
high = sol1 if (sol1>sol2) else sol2 #binary search range initialization with positive solution | ||
low = math.floor(math.sqrt(len(keypoints)/num_ret_points)) | ||
|
||
prevWidth = -1 | ||
selected_keypoints = [] | ||
ResultVec = [] | ||
result = [] | ||
complete = False | ||
K = num_ret_points | ||
Kmin = round(K-(K*tolerance)) | ||
Kmax = round(K+(K*tolerance)) | ||
|
||
while(~complete): | ||
width = low+(high-low)/2 | ||
if (width == prevWidth or low>high): #needed to reassure the same radius is not repeated again | ||
ResultVec = result #return the keypoints from the previous iteration | ||
break | ||
|
||
c = width/2; #initializing Grid | ||
numCellCols = int(math.floor(cols/c)); | ||
numCellRows = int(math.floor(rows/c)); | ||
coveredVec = [ [False for i in range(numCellCols+1)] for j in range(numCellCols+1)] | ||
result = [] | ||
|
||
for i in range(len(keypoints)): | ||
row = int(math.floor(keypoints[i].pt[1]/c)) #get position of the cell current point is located at | ||
col = int(math.floor(keypoints[i].pt[0]/c)) | ||
if (coveredVec[row][col]==False): # if the cell is not covered | ||
result.append(i) | ||
rowMin = int((row-math.floor(width/c)) if ((row-math.floor(width/c))>=0) else 0) #get range which current radius is covering | ||
rowMax = int((row+math.floor(width/c)) if ((row+math.floor(width/c))<=numCellRows) else numCellRows) | ||
colMin = int((col-math.floor(width/c)) if ((col-math.floor(width/c))>=0) else 0) | ||
colMax = int((col+math.floor(width/c)) if ((col+math.floor(width/c))<=numCellCols) else numCellCols) | ||
for rowToCov in range(rowMin, rowMax+1): | ||
for colToCov in range(colMin, colMax+1): | ||
if (~coveredVec[rowToCov][colToCov]): | ||
coveredVec[rowToCov][colToCov] = True #cover cells within the square bounding box with width w | ||
|
||
if (len(result)>=Kmin and len(result)<=Kmax): #solution found | ||
ResultVec = result | ||
complete = True | ||
elif (len(result)<Kmin): | ||
high = width-1 #update binary search range | ||
else: | ||
low = width+1 | ||
prevWidth = width | ||
|
||
for i in range(len(ResultVec)): | ||
selected_keypoints.append(keypoints[ResultVec[i]]) | ||
|
||
return selected_keypoints |
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