Go to Post Hyper, I want to marry your robot. - Keys [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 02-11-2012, 09:44 AM
Yppiz's Avatar
Yppiz Yppiz is offline
Registered User
FRC #1014 (Bad Robots)
Team Role: Programmer
 
Join Date: Feb 2010
Rookie Year: 1776
Location: Dublin,OH
Posts: 33
Yppiz is an unknown quantity at this point
Image processing lag

We just added image processing from the AxisCamera, and our robot began lagging quite a bit. Our CPU use goes to 100 percent on the robot once we try to analyze the image. Is there any way to fix this? This is our code:

Code:
public ParticleAnalysisReport[] getRectangleParticles() throws AxisCameraException, NIVisionException
    {
        ParticleAnalysisReport[] toReturn = new ParticleAnalysisReport[0];

        trial++;
        int current = 0;
        
        try 
        {
            //gets and stores the current camera image
            img = AxisCamera.getInstance().getImage();

            //Created a binary image where pixels meeting threshold
            BinaryImage binary = img.thresholdHSL(0, 1, 0, 1, 0, 1);
            img.thresholdHSL(0, 1, 0, 1, 0, 1);
            //Array of all detected rectangles, right?
            ParticleAnalysisReport[] particles = binary.getOrderedParticleAnalysisReports();

            //Makes checks to see if the rectangle meets size and ratio requirements
            for (int i = 0; i < particles.length; i++)
            {
                ParticleAnalysisReport test = particles[i];
                if (test.particleToImagePercent > .1 && test.particleToImagePercent < .4)
                {
                    double ratio = test.boundingRectWidth/test.boundingRectHeight;
                    if (ratio > ((4/3) - .2) && ratio < ((4/3) + .2))
                    {
                        toReturn = new ParticleAnalysisReport[toReturn.length + 1];
                        System.out.println("Trial: " + trial + "Current: " + current + "Raw: " + particles.length);
                        toReturn[current] = test;
                        current++;
                    }
                }
            }

            //release memory allocated to the images
            //img.free();
            binary.free();
        }
        
        catch (NIVisionException ex)
        {
            ex.printStackTrace();
        }

        //return the rectangles that meet the requirements
        System.out.println("Trial: " + trial);
        return toReturn;
    }
__________________
My friend VICTOR has a JAGUAR and a 2CAN, and from his Lab'sVIEW he can CRIO grande. Do the puns have you VEXed? You're not the FIRST.
Reply With Quote
  #2   Spotlight this post!  
Unread 02-11-2012, 01:31 PM
Patrick Chiang Patrick Chiang is offline
Programming
FRC #3070 (Team Pronto)
Team Role: Mentor
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Seattle
Posts: 162
Patrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to all
Re: Image processing lag

Lag and 100% CPU? Are you calling getRectangleParticles() repeatedly in teleopPeriodic or teleopContinuous without starting vision processing as another thread?
Reply With Quote
  #3   Spotlight this post!  
Unread 02-11-2012, 01:56 PM
jesusrambo jesusrambo is offline
Self-Proclaimed Programmer Messiah
AKA: JD Russo
FRC #2035 (Robo Rockin' Bots)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2010
Location: Carmel, CA
Posts: 114
jesusrambo is an unknown quantity at this point
Re: Image processing lag

The part of your code we'll need to see are your teleopPeriodic() and teleopContinuous() loops. My bet is that you're trying to run your image processing at the beginning of one of those, and the whole robot has to stop while it waits for the image processing operations to clear.
Reply With Quote
  #4   Spotlight this post!  
Unread 02-12-2012, 03:45 AM
ItzWarty ItzWarty is offline
Registered User
FRC #1072 (Harker Robotics)
Team Role: Leadership
 
Join Date: Jan 2012
Rookie Year: 2010
Location: California
Posts: 15
ItzWarty is an unknown quantity at this point
Re: Image processing lag

Try using a timer class to see the elapsed ms of each method invocation.

Are you calling the method a ton of times? Are you checking if you have a new image?
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 09:02 AM.

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