|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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;
Any help would be greatly appreciated. |
|
#2
|
|||
|
|||
|
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.
|
|
#3
|
||||
|
||||
|
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);
}
}
|
|
#4
|
||||
|
||||
|
Re: GetParticleAnalysisReport causes crash
Quote:
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. |
|
#5
|
||||
|
||||
|
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;
bob |
|
#6
|
|||
|
|||
|
Re: GetParticleAnalysisReport causes crash
Thank you all very much. It's working now.
|
|
#7
|
||||
|
||||
|
Re: GetParticleAnalysisReport causes crash
Would you share how you solved your problem so other people can learn from it?
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|