Camera bug

sumtin 0.0000000

Hi! Im trying to get my camera working. Above is my output (should be num targets followed by fraction of distance of the first target to center)
I made this simple V of code to debug but no luck
help plz

#include “WPILib.h”
#include “nivision.h”
#include <stdlib.h>
#define IO (DriverStation::GetInstance()->GetEnhancedIO())
static AxisCamera &camera = AxisCamera::GetInstance(“”);
//output from cameras to driverstation (so we can see it)
static ColorImage image(IMAQ_IMAGE_HSL);
//create an image to buffer pics
static DriverStationLCD* driverOut = DriverStationLCD::GetInstance();
BinaryImage* binImg;
class RobotDemo : public SimpleRobot
Joystick stick; // only joystick

stick(1) // as they are declared above.
binImg = image.ThresholdHSL(0, 250, 30, 200, 130, 270);
//white balance – set manually via internet connection w/hold
//low color
//lower easier on CRIO and harder on cam
void Autonomous(void)
void OperatorControl(void)
while (IsOperatorControl())
vector<ParticleAnalysisReport>* particles = binImg->GetOrderedParticleAnalysisReports();
ParticleAnalysisReport& par = (*particles)[1];
if (stick.GetRawButton(1))
driverOut->PrintfLine(DriverStationLCD::kUser_Line1, “Z: %n”, particles->size());//output num targets
driverOut->PrintfLine(DriverStationLCD::kUser_Line2, “sumtin %f”, par.center_mass_y);
//output fraction of anle to target 1 in center of screen


The vision targeting code is a lot more complicated than what you have here. Please refer to the VisionSample2012 code. If you downloaded update 3111 from here, you should have that example code.

Also, a quick scan of your code showed that you are not printing the numbers correctly.

driverOut->PrintfLine(DriverStationLCD::kUser_Line1, "Z: %n", particles->size());//output num targets
driverOut->PrintfLine(DriverStationLCD::kUser_Line2, "sumtin %f", par.center_mass_y);

If I am guessing what you are trying to do correctly, it should be: (both fields are integers).

driverOut->PrintfLine(DriverStationLCD::kUser_Line1, "Z: %d", particles->size());//output num targets
driverOut->PrintfLine(DriverStationLCD::kUser_Line2, "sumtin %d", par.center_mass_y);

This example makes life 1000* easier. thanks for pointing the way

image = new RGBImage("/10ft2.jpg");

How do I get ‘/10ft2.jpg’ from the camera instead?

camera.GetImage() <returns a HSL image. Can I convert this in C++ to RGB instead of by the vision assistant software?

AxisCamera::GetImage has three overloads. One takes a ColorImage* as parameter.

int AxisCamera::GetImage(ColorImage* image)

nvm got it!

ColorImage image(IMAQ_IMAGE_RGB);
BinaryImage *thresholdImage = image.ThresholdRGB(threshold);
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

driverOut-&gt;PrintfLine(DriverStationLCD::kUser_Line2, "Target Select, numTargets: %n", (int)particles-&gt;size());

delete particles;
delete filteredImage;
delete convexHullImage;
delete bigObjectsImage;
delete thresholdImage;
delete ℑ

Okay-> I modified my code to match theirs. There are probably still a few bugs so I’d appreciate someone’s glancing at it. The functions I’m interested in right now are all above autonomous and operator control. sorry it’s a little messy right now; I’ll put everything in classes and such later

Doc8.cpp (14 KB)

Doc8.cpp (14 KB)

tested today and messed with it more. everything works now. thanks

When ever we do this (call GetImage()) the resulting image has 0 height and width. It seems like we are not getting back an image.

We are at somewhat of a loss to work out what we’re doing wrong.

Pointers or suggestions for debugging would be great.


I’ve seen this happen if the camera isn’t initialized – but if you’re doing the GetImage() repeatedly during a loop, then it’s unlikely that.

If you haven’t set the Brightness, that could do it – so be sure to do camera.SetBrightness(40) as well.

Post a snip of the code if those hints don’t get you anywhere.



I got that working on and off but then tried to use the NI Vision Assistant to make better tracking code.

I eliminated some issues and incorporated it with robot code but still am having some troubles: there are a few errors and I’m not sure how to get the values I’m interested in… though I am more secure about figuring the later out.

the errors in the C file seem to be related (there are five)

The three files are rather long so I attached them.

thanks! : |)

camera tracking (5.61 KB)

camera tracking (5.61 KB)