MCPcopy Index your code
hub / github.com/makelove/OpenCV-Python-Tutorial / preprocess_hog

Function preprocess_hog

官方samples/digits.py:128–148  ·  view source on GitHub ↗
(digits)

Source from the content-addressed store, hash-verified

126 return np.float32(digits).reshape(-1, SZ*SZ) / 255.0
127
128def preprocess_hog(digits):
129 samples = []
130 for img in digits:
131 gx = cv2.Sobel(img, cv2.CV_32F, 1, 0)
132 gy = cv2.Sobel(img, cv2.CV_32F, 0, 1)
133 mag, ang = cv2.cartToPolar(gx, gy)
134 bin_n = 16
135 bin = np.int32(bin_n*ang/(2*np.pi))
136 bin_cells = bin[:10,:10], bin[10:,:10], bin[:10,10:], bin[10:,10:]
137 mag_cells = mag[:10,:10], mag[10:,:10], mag[:10,10:], mag[10:,10:]
138 hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]
139 hist = np.hstack(hists)
140
141 # transform to Hellinger kernel
142 eps = 1e-7
143 hist /= hist.sum() + eps
144 hist = np.sqrt(hist)
145 hist /= norm(hist) + eps
146
147 samples.append(hist)
148 return np.float32(samples)
149
150
151if __name__ == '__main__':

Callers 3

preprocessMethod · 0.85
digits.pyFile · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected