Ask Your Question

Revision history [back]

Speeding up HOG compute in Java

I have code like this

def hog_single(img):
samples=[]
gx = cv2.Sobel(img, cv2.CV_32F, 1, 0)
gy = cv2.Sobel(img, cv2.CV_32F, 0, 1)
mag, ang = cv2.cartToPolar(gx, gy)
bin_n = 16
bin = np.int32(bin_n*ang/(2*np.pi))
bin_cells = bin[:100,:100], bin[100:,:100], bin[:100,100:], bin[100:,100:]
mag_cells = mag[:100,:100], mag[100:,:100], mag[:100,100:], mag[100:,100:]
hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]
hist = np.hstack(hists)

# transform to Hellinger kernel
eps = 1e-7
hist /= hist.sum() + eps
hist = np.sqrt(hist)
hist /= norm(hist) + eps

samples.append(hist)
return np.float32(samples)

That code from https://github.com/arijitx/HandGesturePy using HOG for hand gesture. my question is how to write that code for speeding up my HOG.compute() in Java ? Because i dont know how to reinvent this part into java please help me.

Speeding up HOG compute in Java

I have the phyton code like this

def hog_single(img):
samples=[]
gx = cv2.Sobel(img, cv2.CV_32F, 1, 0)
gy = cv2.Sobel(img, cv2.CV_32F, 0, 1)
mag, ang = cv2.cartToPolar(gx, gy)
bin_n = 16
bin = np.int32(bin_n*ang/(2*np.pi))
bin_cells = bin[:100,:100], bin[100:,:100], bin[:100,100:], bin[100:,100:]
mag_cells = mag[:100,:100], mag[100:,:100], mag[:100,100:], mag[100:,100:]
hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]
hist = np.hstack(hists)

# transform to Hellinger kernel
eps = 1e-7
hist /= hist.sum() + eps
hist = np.sqrt(hist)
hist /= norm(hist) + eps

samples.append(hist)
return np.float32(samples)

That code from https://github.com/arijitx/HandGesturePy using HOG for hand gesture. my question is how to write that code for speeding up my HOG.compute() in Java ? Because i dont know how to reinvent this part into java please help me.