View Single Post
  #3   Spotlight this post!  
Unread 15-02-2012, 20:14
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Trouble with code for camera

BTW, to make sure it is really a performance issue, add some performance code like below and note how much time it takes to process an image frame. Also, I noticed your code did not delete all the intermediate images. That could cause the cRIO to run out of memory so it would terminate your robot task. Also, try to print out the number of particles found to make sure you don't have an unreasonable amount of false positive targets.
Code:
#define GetMsecTime()           (GetFPGATime()/1000)
if (trigger = stick->GetTrigger())
{
    UINT32 startTime = GetMsecTime();
    if (camera.IsFreshImage())
    {
        HSLImage *image = camera.GetImage();
        BinaryImage *thresholdImage = image->ThresholdHSL(threshold);    // get just the red target pixels
        BinaryImage *bigObjectsImage = thresholdImage->RemoveSmallObjects(false, 2);  // remove small objects (noise)
        BinaryImage *convexHullImage = bigObjectsImage->ConvexHull(false);  // fill in partial and full rectangles
        BinaryImage *filteredImage = convexHullImage->ParticleFilter(criteria, 2);  // find the rectangles
        vector<ParticleAnalysisReport> *reports = filteredImage->GetOrderedParticleAnalysisReports();  // get the results
        printf("Elapsed time = %d\n", GetMsecTime() - startTime);
        printf("Num particles found = %d\n", reports->size());
        int b = 0;
        for (unsigned i = 0; i < reports->size(); i++) 
        {
            ParticleAnalysisReport *r = &(reports->at(i));
            DS->DriverStationLCD:Printf(DriverStationLCD::kUser_Line1,1,"Particle: %d  center_mass: %d \n",r->center_mass_x);
            //DS->DriverStationLCD::UpdateLCD();
            //printf("particle: %d  center_mass_x: %d\n", i, r->center_mass_x);
            b = r->center_mass_x;
        }
        delete reports;
        delete filteredImage;
        delete convexHullImage;
        delete bigObjectsImage;
        delete thresholdImage;
        delete image;
    }
}
__________________

Last edited by mikets : 15-02-2012 at 20:17.
Reply With Quote