eduardolundgren / tracking.js

A modern approach for Computer Vision on the web
http://trackingjs.com
Other
9.44k stars 1.45k forks source link

Significant performance drop in Google Chrome #118

Open kudlohlavec opened 9 years ago

kudlohlavec commented 9 years ago

I got performance issues with face tracking algorithm in google chrome browser (version 42.0.2311.90 m). In firefox everything goes smooth - in your demo on http://trackingjs.com/examples/face_camera.html it gives me around 30 FPS while in chrome performance drops to 11 FPS. I got pretty strong setup of hardware so that should not be the problem. CPU load is similar in firefox and chrome (around 20%). I also tried it on weaker machines and the performance drop was much stronger. My Hardware: i7-4710HQ 2.50GHz 8GB RAM

stevekinney commented 9 years ago

I can confirm that I'm experiencing a similar issue.

eduardolundgren commented 9 years ago

If possible, provide an example html with the code that is running slow. Many factors could affect performance, canvas size, track handlers etc.

Thank you for reporting.

stevekinney commented 9 years ago

The demo on the tracking.js website is actually a great example.

http://trackingjs.com/examples/face_camera.html

On May 15, 2015 at 2:13:59 AM, Eduardo Lundgren (notifications@github.com) wrote:

If possible, provide an example html with the code that is running slow. Manu factors could affect performance, canvas size, track handlers etc.

Thank you for reporting.

— Reply to this email directly or view it on GitHub.

carloshpds commented 8 years ago

+1 The same code on firefox is much faster than on Google Chrome. I'm trying to figure out why that happens.

jhn commented 8 years ago

Same here. Stopping the tracker in Chrome brings video performance back to normal, enabling it completely kills it. In Firefox I don't see the problem.

Tracking on a 640x480 video element. Running Chrome Version 48.0.2564.23 beta (64-bit).

eduardolundgren commented 8 years ago

Please, post here any conclusion. Thank you guys.

sduenser commented 8 years ago

Hey guys!

I've experienced the same issue, and believe to have found the solution.

ViolaJones.js uses Int32Arrays (e.g. line 47); it seems those perform rather poorly on Chrome. Replacing them with generic arrays ( i.e. ... = new Array(arraysize); ) solved the problem for me. As far as I could measure this change didn't cause any performance drop in Firefox; also IE11 and Safari perform well with the fix (although for those I have no comparison with the original Int32-version.)

I hope this can help.

Awesome project by the way, keep up the good work!

Cheers, Simon

carloshpds commented 8 years ago

Oh man! I'm gonna try this later.. :smile: :+1:

ianni67 commented 6 years ago

Anyone who experienced the same issue, and solved the same way as @sduenser ? My chrome is terribly slow and I have to decide if I should go for some other library or try to modify the code.

tetreault commented 6 years ago

Hey, i posted this on #182 but will post it here since its relevant @ianni67

I built a project using trackingjs for eye detection on video and images. on desktops the video was fine on my 2017 MBP but was running horribly on peoples laptops that had CPUs < 2Ghz.

Inside of tracking.trackVideo I just slightly modified the resizeCanvas_ function to just set the width and height of the internal canvas by half and that significantly improved the experience on these people's laptops that were 3+ years old.

    var resizeCanvas_ = function() {
      width = element.offsetWidth;
      height = element.offsetHeight;
      canvas.width = width / 2; 
      canvas.height = height / 2;
    };
eduardolundgren commented 6 years ago

@tetreault analyzing a smaller canvas is a good idea, feel free to submit a pull request. Is this ever going to report different output coordinates on the tracking callbacks?

tetreault commented 6 years ago

@eduardolundgren thanks for the reply and extra thanks for making this library!

I'd submit a PR with my modified version of the trackingjs library but this was for a client project and I have quite a few gnarly things going on that I added. For example when get the ViolaJones results back from the internal canvas for video tracking I have a (admittedly hacky) group of calculations that run each time that function runs. The functions color averages pixels in the found regions of interest, converts the colors from RGB to LAB so I can calculate a delta E to compare the average color of the pixels to another hardcoded color in LAB form.

I'll freshly clone this repo and toss in that modification for a smaller canvas when I get the chance though!