hey we downloaded the vision sample provided in the wpilib ,and the thing is we don’t know what does it do exactly ,we understood its general function which is identify the rectangle (which is covered with reflective tape ) ,so how do we know exactly that it managed to identify the target ,should it show any cues or something???(our axis camera is set properly and shows live fed ) …
and here is the sample …
#include "WPILib.h"
#include "Vision/RGBImage.h"
#include "Vision/BinaryImage.h"
/**
* Sample program to use NIVision to find rectangles in the scene that are illuminated
* by a red ring light (similar to the model from FIRSTChoice). The camera sensitivity
* is set very low so as to only show light sources and remove any distracting parts
* of the image.
*
* The CriteriaCollection is the set of criteria that is used to filter the set of
* rectangles that are detected. In this example we're looking for rectangles with
* a minimum width of 30 pixels and maximum of 400 pixels. Similar for height (see
* the addCriteria() methods below.
*
* The algorithm first does a color threshold operation that only takes objects in the
* scene that have a significant red color component. Then removes small objects that
* might be caused by red reflection scattered from other parts of the scene. Then
* a convex hull operation fills all the rectangle outlines (even the partially occluded
* ones). Finally a particle filter looks for all the shapes that meet the requirements
* specified in the criteria collection.
*
* Look in the VisionImages directory inside the project that is created for the sample
* images as well as the NI Vision Assistant file that contains the vision command
* chain (open it with the Vision Assistant)
*/
class VisionSample2012 : public SimpleRobot
{
RobotDrive myRobot; // robot drive system
Joystick stick; // only joystick
AxisCamera *camera;
public:
VisionSample2012(void):
myRobot(1, 2), // these must be initialized in the same order
stick(1) // as they are declared above.
{
myRobot.SetExpiration(0.1);
myRobot.SetSafetyEnabled(false);
}
/**
* Drive left & right motors for 2 seconds then stop
*/
void Autonomous(void)
{
Threshold threshold(25, 255, 0, 45, 0, 47);
ParticleFilterCriteria2 criteria] = {
{IMAQ_MT_BOUNDING_RECT_WIDTH, 30, 400, false, false},
{IMAQ_MT_BOUNDING_RECT_HEIGHT, 40, 400, false, false}
};
while (IsAutonomous() && IsEnabled()) {
/**
* Do the image capture with the camera and apply the algorithm described above. This
* sample will either get images from the camera or from an image file stored in the top
* level directory in the flash memory on the cRIO. The file name in this case is "10ft2.jpg"
*
*/
ColorImage *image;
image = new RGBImage("/10ft2.jpg"); // get the sample image from the cRIO flash
BinaryImage *thresholdImage = image->ThresholdRGB(threshold); // get just the red target pixels
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> *reports = filteredImage->GetOrderedParticleAnalysisReports(); // get the results
for (unsigned i = 0; i < reports->size(); i++) {
ParticleAnalysisReport *r = &(reports->at(i));
printf("particle: %d center_mass_x: %d
", i, r->center_mass_x);
}
printf("
");
// be sure to delete images after using them
delete reports;
delete filteredImage;
delete convexHullImage;
delete bigObjectsImage;
delete thresholdImage;
delete image;
}
}
/**
* Runs the motors with arcade steering.
*/
void OperatorControl(void)
{
myRobot.SetSafetyEnabled(true);
while (IsOperatorControl())
{
Wait(0.005); // wait for a motor update time
}
}
};
START_ROBOT_CLASS(VisionSample2012);