Go to Post Oh, for the love of cod, can't you see that Dave is messing with us just for the halibut? When the actual clue comes out, I'm sure we'll all be singing a different tuna. - Pat Fairbank [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 29-01-2012, 23:39
Sinani201 Sinani201 is offline
Registered User
AKA: Daniel
FRC #1836 (Milken Knights)
Team Role: Programmer
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Los Angeles, CA
Posts: 12
Sinani201 is an unknown quantity at this point
GetParticleAnalysisReport causes crash

Whenever I try to use the command GetParticleAnalysisReport, the robot stops working and I have to reboot it. Not sure why this is happening. Here is the code:
Code:
ColorImage* camerain = camera->GetImage();
BinaryImage* binImage = camerain->ThresholdHSL(0,9,0,5,250,255);
int numParticles = binImage->GetNumberParticles();
delete camerain;
ParticleAnalysisReport* report;
for(int i = 1; i<=numParticles; i++)
{
	binImage->GetParticleAnalysisReport(i,report);
	// Other processing stuff
}
delete binImage;
This happens the very first time GetParticleAnalysisReport is called, so it doesn't have to so with overwriting the report variable (though I don't know if this will end up being a problem later).

Any help would be greatly appreciated.
Reply With Quote
  #2   Spotlight this post!  
Unread 29-01-2012, 23:57
basicxman basicxman is offline
Emily Horsman
FRC #2200 (MMRambotics)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Burlington, Ontario
Posts: 971
basicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant future
Send a message via AIM to basicxman Send a message via MSN to basicxman Send a message via Yahoo to basicxman
Re: GetParticleAnalysisReport causes crash

I'm not sure if this would actually cause a crash, but the function you're using ends up calling imaqMeasureParticle which likely takes a zero-indexed particle number. You're starting at 1.
Reply With Quote
  #3   Spotlight this post!  
Unread 30-01-2012, 03:54
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: GetParticleAnalysisReport causes crash

If you take a look at the source code of GetParticleAnalysisReport:
Code:
/**
 * Get a single particle analysis report.
 * Get one (of possibly many) particle analysis reports for an image.
 * This version could be more efficient when copying many reports.
 * @param particleNumber Which particle analysis report to return.
 * @param par the selected particle analysis report
 */
void BinaryImage::GetParticleAnalysisReport(int particleNumber, ParticleAnalysisReport *par)
{
 int success;
 int numParticles = 0;
 success = imaqGetImageSize(m_imaqImage, &par->imageWidth, &par->imageHeight);
 wpi_setImaqErrorWithContext(success, "Error getting image size");
 if (StatusIsFatal())
  return;
 success = imaqCountParticles(m_imaqImage, 1, &numParticles);
 wpi_setImaqErrorWithContext(success, "Error counting particles");
 if (StatusIsFatal())
  return;
 if (particleNumber >= numParticles)
 {
  wpi_setWPIErrorWithContext(ParameterOutOfRange, "particleNumber");
  return;
 }
 par->particleIndex = particleNumber;
 // Don't bother measuring the rest of the particle if one fails
 bool good = ParticleMeasurement(particleNumber, IMAQ_MT_CENTER_OF_MASS_X, &par->center_mass_x);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_CENTER_OF_MASS_Y, &par->center_mass_y);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_AREA, &par->particleArea);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_TOP, &par->boundingRect.top);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_LEFT, &par->boundingRect.left);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_HEIGHT, &par->boundingRect.height);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_WIDTH, &par->boundingRect.width);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_AREA_BY_IMAGE_AREA, &par->particleToImagePercent);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_AREA_BY_PARTICLE_AND_HOLES_AREA, &par->particleQuality);
 if (good)
 {
  /* normalized position (-1 to 1) */
  par->center_mass_x_normalized = NormalizeFromRange(par->center_mass_x, par->imageWidth);
  par->center_mass_y_normalized = NormalizeFromRange(par->center_mass_y, par->imageHeight);
 }
}
You will see that the parameter par is a pointer to the particle analysis report. The code is expecting the pointer is pointing to something. But the code that called the function passed in an uninitialized ParticleAnalysisReport pointer. That will caused an exception for sure. Where did you copy this code from? It should have a line allocating/initializing the ParticleAnalysisReport before passing it to the function.
__________________
Reply With Quote
  #4   Spotlight this post!  
Unread 30-01-2012, 04:08
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: GetParticleAnalysisReport causes crash

Quote:
Originally Posted by Sinani201 View Post
Code:
ColorImage* camerain = camera->GetImage();
BinaryImage* binImage = camerain->ThresholdHSL(0,9,0,5,250,255);
int numParticles = binImage->GetNumberParticles();
delete camerain;
ParticleAnalysisReport* report;
for(int i = 1; i<=numParticles; i++)
{
    binImage->GetParticleAnalysisReport(i,report);
    // Other processing stuff
}
delete binImage;
It looks like the code should have been:
Code:
ColorImage* camerain = camera->GetImage();
BinaryImage* binImage = camerain->ThresholdHSL(0,9,0,5,250,255);
int numParticles = binImage->GetNumberParticles();
delete camerain;
for(int i = 0; i<numParticles; i++)
{
    ParticleAnalysisReport = binImage->GetParticleAnalysisReport(i);
    // Other processing stuff
}
delete binImage;
__________________

Last edited by mikets : 30-01-2012 at 04:22.
Reply With Quote
  #5   Spotlight this post!  
Unread 30-01-2012, 12:00
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 157
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
Re: GetParticleAnalysisReport causes crash

The prior post is fine as well, but if you're still wondering the subtlety of why yours didn't work originally, see the // **CHANGE** line here...

Code:
ColorImage* camerain = camera->GetImage();
BinaryImage* binImage = camerain->ThresholdHSL(0,9,0,5,250,255);
int numParticles = binImage->GetNumberParticles();
delete camerain;
ParticleAnalysisReport report; // **CHANGE** - instantiates the real object and not just a pointer to it...(and then below...)
for(int i = 1; i<=numParticles; i++)
{
    binImage->GetParticleAnalysisReport(i,&report);  // **CHANGE** and now pass the address of the real object to the function so it can make modifications to your real object 'report' from above.
    // Other processing stuff
}
delete binImage;
The only other concern is it should be "for (i=0 ; i<numParticles; i++)" or you'll crash at the tail end of the for-loop for going out of bounds. Arrays in C always start with the '0' element ... not '1'.

bob
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
Reply With Quote
  #6   Spotlight this post!  
Unread 30-01-2012, 18:16
Sinani201 Sinani201 is offline
Registered User
AKA: Daniel
FRC #1836 (Milken Knights)
Team Role: Programmer
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Los Angeles, CA
Posts: 12
Sinani201 is an unknown quantity at this point
Re: GetParticleAnalysisReport causes crash

Thank you all very much. It's working now.
Reply With Quote
  #7   Spotlight this post!  
Unread 30-01-2012, 18:17
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: GetParticleAnalysisReport causes crash

Would you share how you solved your problem so other people can learn from it?
__________________
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 17:39.

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