Log in

View Full Version : simple camera feed and LCD output


Method
13-02-2012, 03:23
Hi!
I was just wanting to check that this is working correctly and make it available if so

I have a problem where enabling code would bring robot code and comms down till i reboot

I made this by cutting huge sections out of my code, simplifying them(I was separating R G and B then comparing particles[in separate files]), then putting them in the vision example

#include "WPILib.h"
#include "Vision/RGBImage.h"
#include "Vision/BinaryImage.h"

#define RL 200
#define RH 260
#define GL 140
#define GH 210
#define BL 90
#define BH 135

static AxisCamera &eyeOfSauron = AxisCamera::GetInstance("10.16.71.11");
DriverStationLCD* driverOut = DriverStationLCD::GetInstance();
//for smart dashboard

class VisionSample2012 : public SimpleRobot
{
DriverStationLCD* driverOut;
Joystick pilot;
public:
VisionSample2012(void):
pilot(1)
{
GetWatchdog().Kill();
driverOut = DriverStationLCD::GetInstance();

//eyeOfSauron.WriteBrightness(30);
//eyeOfSauron.WriteWhiteBalance(AxisCamera::kWhiteBa lance_Hold);
eyeOfSauron.WriteResolution(AxisCamera::kResolutio n_320x240);
//eyeOfSauron.WriteColorLevel(100);
//eyeOfSauron.WriteCompression(30);
//lower easier on CRIO and harder on cam
eyeOfSauron.WriteMaxFPS(5);
}

void Autonomous(void)
{
GetWatchdog().Kill();
while (IsAutonomous() && IsEnabled())
{
GetWatchdog().Kill();
CamAnOut();
}
}
void OperatorControl(void)
{
GetWatchdog().Kill();
while (IsOperatorControl())
{
GetWatchdog().Kill();
CamAnOut();
}
}
void CamAnOut (void)
{
Threshold threshold(RH, RL, GH, GL, BH, BL);
ParticleFilterCriteria2 criteria[] = {
{IMAQ_MT_BOUNDING_RECT_WIDTH, 10, 200, false, false},
{IMAQ_MT_BOUNDING_RECT_HEIGHT, 10, 200, false, false}};
// false Set this element to TRUE to take calibrated measurements.
// fales Set this element to TRUE to indicate that a match occurs when the measurement is outside the criteria range

// ColorImage *image;
// image = new RGBImage("/10ft2.jpg"); // get the sample image from the cRIO flash

ColorImage image(IMAQ_IMAGE_RGB);
//make image
eyeOfSauron.GetImage(&image);
//store camera feed to image
BinaryImage *thresholdImage = image.ThresholdRGB(threshold);
//pixel range
BinaryImage *bigObjectsImage = thresholdImage->RemoveSmallObjects(false, 2);
// remove small objects (noise)
BinaryImage *convexHullImage = bigObjectsImage->ConvexHull(false);
// fill in partial and full rectangles
BinaryImage *filteredImage = convexHullImage->ParticleFilter(criteria, 2);
// find the rectangles
vector<ParticleAnalysisReport> *particles = filteredImage->GetOrderedParticleAnalysisReports();
// get the results

//LCD output
if (IsAutonomous())
driverOut->Printf(DriverStationLCD::kUser_Line1, 1, "Autonomous");
else if (IsOperatorControl())
driverOut->Printf(DriverStationLCD::kUser_Line1, 1, "Operat or");

//too many, or too few targets? If not, how many?
if (particles->size() == 0)
driverOut->Printf(DriverStationLCD::kUser_Line2, 1, "loosen filter");
else if (particles->size() > 4)
driverOut->Printf(DriverStationLCD::kUser_Line2, 1, "tighten filter");
else
{ //TRY I
driverOut->Printf(DriverStationLCD::kUser_Line2, 1, "Number of targets: %d", particles->size());
}

//update the LCD on the DS
driverOut->UpdateLCD( );

//delete reports;
delete filteredImage;
delete convexHullImage;
delete bigObjectsImage;
delete thresholdImage;
delete &image;
}
};

START_ROBOT_CLASS(VisionSample2012);

mikets
13-02-2012, 06:55
I did not look at your code very carefully but one thing jumped out:

void CamAnOut (void)
{
Threshold threshold(RH, RL, GH, GL, BH, BL);

I believe you have reversed the High and Low numbers. It should be:

void CamAnOut (void)
{
Threshold threshold(RL, RH, GL, GH, BL, BH);

Method
13-02-2012, 14:20
oh yeah-> retyped that, thanks

Method
13-02-2012, 22:47
I have altered my approach. I just created tracking with the NI Vision Assistant. After doing so and using the tool to create C code, then hooking up to a project, I fixed a few errors in the generated code. I still have two I'm not sure about which occur within the generated c file.

//first instance of the first error
error: invalid conversion from `int' to `MeasurementType'

//only instance of the second error
error: invalid conversion from `void*' to `IVA_Result*'

//second of first error (argument 4 is of type MeasurementType with which I am having the first error)
error: initializing argument 4 of `int imaqMeasureParticle(Image*, int, int, MeasurementType, double*)'

//third of first error
error: initializing argument 4 of `int imaqMeasureParticle(Image*, int, int, MeasurementType, double*)'

Method
13-02-2012, 23:52
//These are filtering the image (how do I do this with the order I created?[is this done by the vision assistant algorithm?])



// BinaryImage *thresholdImage = image.ThresholdRGB(threshold);
// //pixel range
// BinaryImage *bigObjectsImage = thresholdImage->RemoveSmallObjects(false, 2);
// // remove small objects (noise)
// BinaryImage *convexHullImage = bigObjectsImage->ConvexHull(false);
// // fill in partial and full rectangles
// BinaryImage *filteredImage = convexHullImage->ParticleFilter(criteria, 2);
// // find the rectangles



//This is getting the particles' results. will it be the same?



// vector<ParticleAnalysisReport> *particles = filteredImage->GetOrderedParticleAnalysisReports();
//This is selecting a target to output results from
// ParticleAnalysisReport *par = &(particles)->at(choiceTarget);