Menu

High CPU usage

Q3Varnam
2014-07-09
2014-07-10
  • Q3Varnam

    Q3Varnam - 2014-07-09

    I am comparing performance of OpenIMAJ against OpenCV(using Java).

    I am running a simple face detector using haarcascade_frontalface_default.xml as given in OpenIMAJ tutorial.

    I am running it on a dual core AMD A6 laptop with 6GB RAM

    When I run OpenIMAJ version the CPU load is 120% when its detecting faces and 110% when just displaying a video without any faces.

    When I run the OpenCV Java version of the face detector, CPU load is at 60% when detecting faces and 40% when the video without faces is displayed .

    All measured using top command.

    On OpenIMAJ, I have set the frame rate to 4.

    On OpenCV I am using a thread which sleeps for 250ms before it captures a new image from the camera.

    The scaling is set to 1.1 on both OpenCV as well as OpenIMAJ

    On the OpenCV version I am additionally calculating the LBPH histograms before displaying the image.

    I tried forcing OpenIMAJ program to use the GPU by passing -Dprism.forceGPU=true -Dprism.verbose=true but that doesn't make any difference.

    I am running this on Ubuntu 14.04 with Java 8.

    Can you confirm whether this is the normal CPU usage for OpenIMAJ or whether I am missing something which is unnecessarily loading the CPU?

     
  • Jonathon Hare

    Jonathon Hare - 2014-07-09

    This is likely to be something to do with the way the native drivers for your camera handle requests for specific frame rates. Instead of specifying the framerate in your VideoCapture constructor, you could just do the same as you're doing with OCV and sleep the thread:

    final VideoCapture vc = new VideoCapture(640, 480);
    final HaarCascadeDetector hcd = HaarCascadeDetector.BuiltInCascade.frontalface_default.load();
    
    //Either do it this way:
    // for (final MBFImage img : vc) {
    // for (final DetectedFace f : hcd.detectFaces(img.flatten())) {
        // img.drawShape(f.getBounds(), RGBColour.RED);
        // }
        // DisplayUtilities.displayName(img, "foo");
        //Thread.sleep(250);
    // }
    
    //or this way:
    VideoDisplay.createVideoDisplay(vc).addVideoListener(new VideoDisplayAdapter<MBFImage>() {
    @Override
    public void beforeUpdate(MBFImage frame) {
        for (final DetectedFace f : hcd.detectFaces(frame.flatten())) {
        frame.drawShape(f.getBounds(), RGBColour.RED);
        }
        try { Thread.sleep(250); } catch (final InterruptedException e) {}
    }
    });
    

    In my tests I'm seeing ~55% CPU usage with either of these approaches (and getting similar results to you (~120% usage) if I ask the native camera drivers to provide me with a 4 fps stream). JVisualVM indicates that the bit taking the most CPU time in the case where the frame rate is set to 4 fps is in the native call to grabber.getImage() inside VideoCapture.getNextFrame().

    Note that if you want to improve the performance of the face detector, setting the minimum detection size to be larger is a good place to start.

     
  • Q3Varnam

    Q3Varnam - 2014-07-10

    With your suggestion things have improved far better, your code outperforms OpenCV while using most of the cascade files,









    Cascade file used OpenIMAJ CPU Usage OpenCV(Java) CPU

    frontalface_default
    20 50

    frontalface_alt
    12 40
    frontalface_alt2 12 40
    frontalface_alt_tree 55 40

    I am not sure why the scroll bar is not appearing for the table

    Unformatted values are below if you can't read the table

    frontalface_default 20 50
    frontalface_alt 12 40
    frontalface_alt2 12 40
    frontalface_alt_tree 55 40

     

    Last edit: Q3Varnam 2014-07-10

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.