Speeding up HOG compute in Java [closed]

asked 2018-04-08 14:25:42 -0500

updated 2018-04-08 14:26:24 -0500

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.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by EdoTwentySix
close date 2018-04-21 09:03:30.218785

Comments

you are not using HOGDescriptor.compute() , which is parallelized, and SSE/AVX optimized.

don't reinvent the wheel, and profit from opencv's effort at optimization.

berak gravatar imageberak ( 2018-04-09 02:30:00 -0500 )edit

What a SSE/AVX optimized means ?

EdoTwentySix gravatar imageEdoTwentySix ( 2018-04-09 06:01:44 -0500 )edit

vector operations, like multiplying 4 numbers at a time

berak gravatar imageberak ( 2018-04-09 06:06:51 -0500 )edit

How can i implement that in my HOG ?

EdoTwentySix gravatar imageEdoTwentySix ( 2018-04-09 06:18:44 -0500 )edit

you can't in java. that's why you should not reinvent it.

berak gravatar imageberak ( 2018-04-09 06:36:29 -0500 )edit

Thanks in advance !

EdoTwentySix gravatar imageEdoTwentySix ( 2018-04-09 06:50:09 -0500 )edit