|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| 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:
|
|
#2
|
|||
|
|||
|
Re: WPILib vision error in ColorImage.cpp and BinaryImage.cpp
Here is line 37 of the ColorImage.cpp
Code:
BinaryImage * ColorImage::ComputeThreshold(ColorMode colorMode,
int low1, int high1,
int low2, int high2,
int low3, int high3)
{
BinaryImage *result = new BinaryImage();
Range range1 = {low1, high1},
range2 = {low2, high2},
range3 = {low3, high3};
int success = imaqColorThreshold(result->GetImaqImage(),
m_imaqImage, 1, colorMode, &range1, &range2, &range3);
wpi_imaqAssert(success, "ImaqThreshold error");
//here's the assert that's producing the error. What can I do to fix this?
return result;
}
Thanks. |
|
#3
|
|||
|
|||
|
Re: WPILib vision error in ColorImage.cpp and BinaryImage.cpp
That's an obnoxious assert.
But the problem is likely one of two things, you end up running out of memory or you are passing in an image of zero size (likely the second one). Check that your image has a size before you do any operations on it. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|