-
-
Notifications
You must be signed in to change notification settings - Fork 47.1k
Added Harris Feature Detector to Digital Image Processing #801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,20 @@ | ||
# Computation of Harris Detector | ||
|
||
## Dependencies | ||
|
||
- opencv-python | ||
- Numpy | ||
- Scipy | ||
|
||
## Steps | ||
|
||
Given image $I$, $n\times n$ size Gaussian Kernel $G_{n\times n}$, | ||
|
||
1. Compute the gradients of the image, both horizontal and vertical directions. $X=(-1, 0, 1)\otimes I$, $Y=(-1, 0, 1)^T \otimes I$ | ||
2. Compute the matrix $M$, where $A = G_{n\times n} \otimes X^2$, $B=G_{n\times n}\otimes Y^2$, $C=G_{n\times n}\otimes XY$ | ||
3. Compute the response function $R$, where $R=AB-C^2-k(A+B)$ | ||
4. Classify all points in $R$. | ||
|
||
## Reference | ||
|
||
C. Harris and M. Stephens, “A Combined Corner and Edge Detector,” in Proceedings of Alvey Vision Conference 1988, Manchester, 1988, pp. 23.1-23.6. |
This file contains hidden or 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,35 @@ | ||
""" | ||
Implementation of Harris Detector | ||
|
||
Reference: | ||
C. Harris and M. Stephens, “A Combined Corner and Edge Detector,” | ||
in Proceedings of Alvey Vision Conference 1988, Manchester, 1988, pp. 23.1-23.6. | ||
""" | ||
|
||
import cv2 as cv | ||
import numpy as np | ||
from scipy.signal import convolve2d | ||
|
||
# Read original image and get gaussian kernel | ||
img = cv.imread('example.png') | ||
img_gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) | ||
|
||
G = cv.getGaussianKernel(3, 1) | ||
|
||
# Begin Harris Detector Computation | ||
|
||
I = img_gray.astype('float32') | ||
X = convolve2d(I, [[-1, 0, 1]], mode='same') | ||
Y = convolve2d(I, [[-1], [0], [1]], mode='same') | ||
A = convolve2d(X*X, G, mode='same') | ||
B = convolve2d(Y*Y, G, mode='same') | ||
C = convolve2d(X*Y, G, mode='same') | ||
R = A*B - C*C - 0.04 * (A + B) | ||
|
||
# Finished Harris Detector Computation | ||
|
||
# Classify all points in R and show corners in image | ||
maxima = np.max(R) | ||
img[R > maxima*0.1] = [255, 0, 0] | ||
cv.imshow('harris_detector', img) | ||
cv.waitKey(0) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be really helpful if you can add this file in Algorithms-Explanation repo. That will help us in future to organise the code and documentation and parse them using scripts.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already Added. Pull request 34.