Created
February 27, 2014 12:13
-
-
Save louist87/9248952 to your computer and use it in GitHub Desktop.
Vectorized HOG feature detector for SimpleCV images
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
def findHOGFeatures(self, n_divs=3, n_bins=6): | |
""" | |
**SUMMARY** | |
Get HOG(Histogram of Oriented Gradients) features from the image. | |
**PARAMETERS** | |
* *n_divs* - the number of divisions(cells). | |
* *n_divs* - the number of orientation bins. | |
**RETURNS** | |
Returns the HOG vector in a numpy array | |
""" | |
n_HOG = n_divs * n_divs * n_bins # Size of HOG vector | |
HOG = np.zeros((n_HOG, 1)) # Initialize output HOG vector | |
# Apply sobel on image to find x and y orientations of the image | |
Icv = self.getNumpyCv2() | |
Ix = cv2.Sobel(Icv, ddepth=cv.CV_32F, dx=1, dy=0, ksize=3) | |
Iy = cv2.Sobel(Icv, ddepth=cv.CV_32F, dx=0, dy=1, ksize=3) | |
Ix = Ix.transpose(1, 0, 2) | |
Iy = Iy.transpose(1, 0, 2) | |
cellx = self.width / n_divs # width of each cell(division) | |
celly = self.height / n_divs # height of each cell(division) | |
# Area of image | |
img_area = self.height * self.width | |
#Range of each bin | |
BIN_RANGE = (2 * pi) / n_bins | |
angles = np.arctan2(Iy, Ix) | |
magnit = ((Ix ** 2) + (Iy ** 2)) ** 0.5 | |
height, width = self.height, self.width | |
bins = (angles[...,0] % (2 * pi) / BIN_RANGE).astype(int) | |
x, y = np.mgrid[:width, :height] | |
x = x * n_divs // width | |
y = y * n_divs // height | |
labels = (x * n_divs + y) * n_bins + bins | |
index = np.arange(n_HOG) | |
HOG = ndi_sum(magnit[..., 0], labels, index) | |
return HOG / self_area |
i want to get return a featureset like the other function in the imageclass that i can draw() or crop().
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello! i am a newbie in python. bought a book to learn simplecv. want to develop my first application for fun.
I have realised if i want to track a person, i need to use HOG. i saw the code that you posted.
i got return an array.
i would like to know what I can do with this array??
thank you very much.