Hi yall,
I am playing around with WPILib for vision and all I am doing is thresholding a colorimage acquired from the axis camera into a binaryimage and then getting a particleanalysisreport vector from that image. Then, I simply find out the center of mass of the two particles.
All I am doing is calling for print statements for NumOfParticles(), IsTargetFound(), and CenterOfMass() in my autonomous code (Functions defined below).
All of these are outputting exactly what I expect, but, after about 5 seconds, errors alternate between
“Error on line 37 of ColorImage.cpp: 0: ImaqThreshold error” and
“Error on line 30 of BinaryImage.cpp: 0: Error counting particles”.
Then, autonomous stops and driver station shows “No Robot Code”.
Here’s the code of my Vision class:
//Vision.h
#pragma once
#include "WPILib.h"
#include <vector>
namespace Subsystems {
class Vision {
private:
AxisCamera* axis;
ColorImage* ci;
BinaryImage* bi;
std::vector<ParticleAnalysisReport>* particles;
void GetImage();
public:
Vision();
~Vision();
int NumOfParticles();
bool IsTargetFound();
int CenterOfMass();
};
}
//Vision.cpp
#include "Vision.h"
namespace Subsystems {
Vision::Vision() { //note the vector "particles" is not initialized. I didn't find a need to
axis = new AxisCamera("10.30.21.11");
axis->WriteResolution(AxisCamera::kResolution_160x120);
ci = new ColorImage(ImageType::IMAQ_IMAGE_RGB);
bi = new BinaryImage();
}
Vision::~Vision() {
delete axis;
delete ci;
delete bi;
}
//private functions
void Vision::GetImage() {
ci = axis->GetImage();
bi = ci->ThresholdRGB(0,255,175,255,0,255); //use green LED
}
//public functions
int Vision::NumOfParticles() {
GetImage();
return bi->GetNumberParticles();
}
bool Vision::IsTargetFound() {
if(NumOfParticles()==2) return true;
return false;
}
int Vision::CenterOfMass() {
if(!IsTargetFound()) return false;
particles = bi->GetOrderedParticleAnalysisReports(); //this is a pointer to a vector
int center_mass = ((*particles)[0].center_mass_x+ (*particles)[1].center_mass_x)/2;
//the center of mass of the two vision targets
particles->clear(); //clear vector
return center_mass;
}
}
Why do you think the program just stops like that with these strange errors?
Error on line 37 of ColorImage.cpp: 0: ImaqThreshold error
at /home/lvuser/FRCUserProgram() [0x1a8e8]
at /home/lvuser/FRCUserProgram() [0x1a964]
at /home/lvuser/FRCUserProgram() [0x1084c]
at /home/lvuser/FRCUserProgram() [0x10878]
at /home/lvuser/FRCUserProgram() [0x108b8]
at /home/lvuser/FRCUserProgram() [0x11124]
at /home/lvuser/FRCUserProgram() [0x1a350]
at /home/lvuser/FRCUserProgram() [0x11570]
at /home/lvuser/FRCUserProgram() [0x1057c]
at __libc_start_mainError on line 30 of BinaryImage.cpp: 0: Error counting particles
at /home/lvuser/FRCUserProgram() [0x1b694]
at /home/lvuser/FRCUserProgram() [0x10888]
at /home/lvuser/FRCUserProgram() [0x108b8]
at /home/lvuser/FRCUserProgram() [0x11124]
at /home/lvuser/FRCUserProgram() [0x1a350]
at /home/lvuser/FRCUserProgram() [0x11570]
at /home/lvuser/FRCUserProgram() [0x1057c]
at __libc_start_main