|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
WPILib vision error in ColorImage.cpp and BinaryImage.cpp
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: Code:
//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();
};
}
Code:
//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;
}
}
Quote:
|
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|