Go to Post I think the best driver team of the post season would be Mike Wade and Pete Baltzell- because they have been driving that NASA field all over the Northeast so all of us can play.Thanks guys!! - Wayne C. [more]
Home
Go Back   Chief Delphi > FIRST > General Forum
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 09-02-2012, 16:32
violinuxer violinuxer is offline
Registered User
FRC #2523
 
Join Date: Jan 2012
Location: Vermont
Posts: 13
violinuxer is an unknown quantity at this point
Massive memory leaks in smartdashboard image processing library.

Hi all!

Our team is using the libraries in SmartDashboard (WPIJavaCV) to do our image processing. We are planning to do image processing on a driverstation computer and then send motor values on the robot. We are up to the point where we can detect rectangles (ie the backboard) but we have been noticing huge memory leaks- SmartDashboard will take more than a gigabyte of memory after only a couple minutes. I have managed to narrow the problem down to the highligted line below. It leaks only when that line is in the code regardless of whether this line assigns its result to a variable. I have been monitoring the code with JVisualVM, which shows a memory usage of under 10MB in java, while the task manager reads usages in the hundreds of MB. Is this a bug in OpenCV? It could make sense due to the fact that JavaCV is just a wrapper of the c version...

Code:
    public WPIImage processImage(WPIColorImage rawImage) {
        int cameraCenterX = rawImage.getWidth() - (rawImage.getWidth() / 2);
        int cameraCenterY = rawImage.getHeight() - (rawImage.getHeight() / 2);
        threshold = thresholdDialog.getThreshold();
        WPIBinaryImage redChannel;
        WPIBinaryImage greenChannel;
        WPIBinaryImage blueChannel;
        WPIBinaryImage finalImage;
        if (thresholdDialog.isInverted()) {
            redChannel = rawImage.getRedChannel().getThreshold(threshold);
            greenChannel = rawImage.getGreenChannel().getThreshold(threshold);
            blueChannel = rawImage.getBlueChannel().getThreshold(threshold);
        } else {
            redChannel = rawImage.getGreenChannel().getThresholdInverted(threshold);
            greenChannel = rawImage.getGreenChannel().getThresholdInverted(threshold);
            blueChannel = rawImage.getGreenChannel().getThresholdInverted(threshold);
        }
        finalImage = redChannel.getAnd(greenChannel.getAnd(blueChannel));

        finalImage.erode(thresholdDialog.getErodeLevel());
        finalImage.dilate(thresholdDialog.getDilateLevel());
        WPIContour[] contours = finalImage.findContours(); // This line causes the memory leak even without assigning to a variable.
        minSize = thresholdDialog.getMinSize();
        maxSize = thresholdDialog.getMaxSize();
        int rectCenterX = 0;
        int rectCenterY = 0;
        int aspectRatio = 0;
        int polyAccuracy = thresholdDialog.getPolyAccuracy();
        
        for (int i = 0; i < contours.length; i++) {
            aspectRatio = contours[i].getWidth() / contours[i].getHeight();
            if (contours[i].getHeight() > minSize && contours[i].getWidth() > minSize && 
                   contours[i].getHeight() < maxSize && contours[i].getWidth() < maxSize) {
                if (aspectRatio < 1.5 && aspectRatio > .75) {
                    WPIPolygon currPolygon = contours[i].approxPolygon(polyAccuracy);
                    if (currPolygon.isConvex() && currPolygon.getNumVertices() == 4) {
                        rectCenterX = currPolygon.getX() + currPolygon.getWidth() / 2;
                        rectCenterY = currPolygon.getY() + currPolygon.getHeight()/ 2;

                        rawImage.drawPolygon(currPolygon, WPIColor.RED, 2);
                        rawImage.drawPoint(new WPIPoint(rectCenterX, rectCenterY), WPIColor.GREEN, 5);
                        rawImage.drawPoint(new WPIPoint(cameraCenterX, cameraCenterY), WPIColor.BLUE, 5);
                    }
                }
            }
        }
        return rawImage; 
    }
}
If anybody has used the same methods successfully, please do post! The knowledge would be greatly appreciated!

Thanks!

violinuxer
Reply With Quote
  #2   Spotlight this post!  
Unread 09-02-2012, 16:58
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,580
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Massive memory leaks in smartdashboard image processing library.

You might look at the latest svn for smartdashboard. The last commit was labeled "Fixed memory leak with contours."
Reply With Quote
  #3   Spotlight this post!  
Unread 09-02-2012, 17:00
violinuxer violinuxer is offline
Registered User
FRC #2523
 
Join Date: Jan 2012
Location: Vermont
Posts: 13
violinuxer is an unknown quantity at this point
Re: Massive memory leaks in smartdashboard image processing library.

Quote:
Originally Posted by Joe Ross View Post
You might look at the latest svn for smartdashboard. The last commit was labeled "Fixed memory leak with contours."
Oh my... guess it's a good thing I have the source!

Thanks soo much!

violinuxer
Reply With Quote
  #4   Spotlight this post!  
Unread 09-02-2012, 17:01
violinuxer violinuxer is offline
Registered User
FRC #2523
 
Join Date: Jan 2012
Location: Vermont
Posts: 13
violinuxer is an unknown quantity at this point
Re: Massive memory leaks in smartdashboard image processing library.

Quote:
Originally Posted by Joe Ross View Post
You might look at the latest svn for smartdashboard. The last commit was labeled "Fixed memory leak with contours."
Oh my... I guess its a good thing I have the source!

violinuxer
Reply With Quote
  #5   Spotlight this post!  
Unread 09-02-2012, 17:03
violinuxer violinuxer is offline
Registered User
FRC #2523
 
Join Date: Jan 2012
Location: Vermont
Posts: 13
violinuxer is an unknown quantity at this point
Re: Massive memory leaks in smartdashboard image processing library.

AND.... sorry about the double post....

violinuxer
__________________
May the source be with you!!

(Linux FTW!)
Reply With Quote
  #6   Spotlight this post!  
Unread 09-02-2012, 17:05
dominique dominique is offline
Registered User
FTC #0211 (MK211)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Rochester,NY
Posts: 9
dominique is an unknown quantity at this point
Re: Massive memory leaks in smartdashboard image processing library.

Hi - look at this post
http://www.chiefdelphi.com/forums/sh...ferrerid=46078

I have not experienced any memory leak but I have not been running too long.

Regarding the analysis using WPI - you will see that Paul has posted a wrapper to access the IPLImage underneath. Does using the IPLImage avoids the findcontour and prevents the leak ?

Also I have not found that using the RGB space (= using WPI) allows to identify a specific color - how does it work for you ? Does not the litterature says that color identification is better done using HSV space (therefore the IPLImage) ? This is confusing to me...
Reply With Quote
  #7   Spotlight this post!  
Unread 13-02-2012, 15:19
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 103
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
Re: Massive memory leaks in smartdashboard image processing library.

The following post includes a JAR file and instructions on installing to avoid the memory leak issues when processing images in SmartDashboard:

http://www.chiefdelphi.com/forums/sh...67&postcount=6

NOTE: This is not an official release from the SmartDashboard project. I did build it by checking out the source after I noticed the commit messages related to fixing the memory leak.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 07:24.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi