Go to Post There is nothing wrong with being great and being proud of it. - TubaMorg [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
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 15-02-2012, 18:53
cddp14 cddp14 is offline
Registered User
FRC #1270
 
Join Date: Feb 2007
Location: Clevleand, Oh
Posts: 10
cddp14 is an unknown quantity at this point
Trouble with code for camera

Right now I am working some of the code form the 2010Vision Sample code. Here is what i have.
if (trigger = stick->GetTrigger())
{
//if (trigger != lastTrigger) // if there's a fresh and we're at the previous target heading then
// get a camera image and process it
if (camera.IsFreshImage())
{
// get the camera image

HSLImage *image = camera.GetImage();
//HSLImage *image;
//image = new HSLImage("/10ft2.jpg"); // get the sample image from the cRIO flash
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
int b = 0;
for (unsigned i = 0; i < reports->size(); i++)
{
ParticleAnalysisReport *r = &(reports->at(i));
DS->DriverStationLCD:rintf(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;


}

When I press the trigger to get an image I lose communication with the robot. After a minute or two it robots and I can enable and drive. I tested the orginal code with added printf statements to to get an understanding of how it works and I did not have this problem. Is something wrong with my code?
Reply With Quote
  #2   Spotlight this post!  
Unread 15-02-2012, 20:01
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: 671
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

Vision processing can take a LONG time if you do not have the filtering parameters set correctly (i.e. generating way too many false positive targets). If vision processing takes too much time, it will prevent your main robot loop from "feeding" the watchdog (i.e. setting your motors) and hence causing the SafetyHelper to cut out the motors.

Before you enable the entire code doing vision processing as well as tele-operating/driving the robot, you probably want to disable safety and fully debug the vision processing code before you re-enable safety for driving.
__________________
Reply With Quote
  #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: 671
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
  #4   Spotlight this post!  
Unread 15-02-2012, 20:20
cddp14 cddp14 is offline
Registered User
FRC #1270
 
Join Date: Feb 2007
Location: Clevleand, Oh
Posts: 10
cddp14 is an unknown quantity at this point
Re: Trouble with code for camera

Thanks!!!.
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 03:00.

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