Yppiz
11-02-2012, 09:44
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:
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;
}
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;
}