mtschirs / js-objectdetect

computer vision in your browser - javascript real-time object detection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Copy implementation

inspirit opened this issue · comments

Hi, i'm currently started a library project https://github.com/inspirit/jsfeat
and while working on porting my own version from flash to js of haar detector i found your implementation. so i wonder if u agree to merge your version to jsfeat?
i already implemented faster canny, grayscale and gaussian methods so your version will be even faster and more responsive :).
let me know what u think.
Best.

Hi inspirit,

I do not mind anybody using code of js-objectdetect, however there might be a licensing issue as js-objectdetect is currently released under GPLv3 (I could perhaps switch to MIT).

However, you should perhaps know that the code used in this library was initially created to serve as a "quick" reference implementation for a GPU based face detector (using WebGL). The code is only compatible to stump based HAAR cascades (https://github.com/foo123/HAAR.js supports all cascades) and has not been tested as thoroughly as it perhaps should have been.

Since canny pruning does not really seem to be effective / increase performance at all, I did not really care that much about further optimizing it. Perhaps your gaussian / canny methods might change that.

Concerning the grayscale conversion, I did some jsperf-tests (http://jsperf.com/convert-rgba-to-grayscale). Performing integer operations instead of floating point operations on the image-data seems to increase performance in all browsers except for IE. Adding more code to the body of the loop however does not change that much. Interestingly, the 8-bit shift integer-version decreased detection performance on the test images (http://mtschirs.github.com/js-objectdetect/examples/example_image.htm). This is because OpenCV (HAAR classifier training) uses 0.299_R + 0.587_G + 0.114_B for RGB to grayscale conversion while your 8-bit shift integer code uses approx. 0.301_R + 0.590_G + 0.109_B. Therefore I now use a 10 bit shift which more closely resembles the OpenCV conversion.

Best regards,
Martin

hey, thanx for the info. according to license, yes i use MIT for my code. how ever i put all the info about original author :) anyway i will look at another implementation u mentioned to get best of both worlds. personally i dont think that grayscale conversion coeefs will have any significant impact. i also tested different ways to convert to grayscale:
http://jsperf.com/math-vs-lut-grayscale

to replicate the same grayscale as presented in OpenCV:

var coeff_r = 4899, coeff_g = 9617, coeff_b = 1868;
var pix_gray = ((coeff_r*pix_r + coeff_g*pix_g + coeff_b*pix_b) + 8192) >> 14;

this is using fixed point math to convert float coeffs to integers and then scale back. the same OpenCV used in thei ColorConvert method

"personally i dont think that grayscale conversion coeefs will have any significant impact" - Well, they have. Using your 8-bit shift coefficients, performance is reduced by 33% in http://mtschirs.github.com/js-objectdetect/examples/example_image.htm. A 10 bit shift seems to have much lesser impact on detection performance there. The 14 bit shift you presented is of course even better, however large shift values also seem to reduce run time performance.

Thank you for all the interesting input though, a closer look at your code reveals some interesting js performance tricks.

well taking into account 160x120 image conversion time only about 1-3ms i think we should go 14 bit version to get best detection result. i've updated my grayscale method to this latest coeffs.
and if user wants to run detection on large/original image it wont be realtime in any case and grayscale time doesnt really matter.

yes, you are probably right. It also seems that a bigger shift value only slighly impacts performance on FF while there seems to be no difference for the other browsers.

btw i did first merge of your implementation:
http://inspirit.ru/jsfeat/haar/

seems to work quite nice.

i also implemented different detection algo (BBF) u can take a look here:
http://inspirit.ru/jsfeat/bbf/

Looks good!

MIT or Apache licenses would be ideal! I'd love to be able to use and contribute back to this project!

...just moved to the MIT license