Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Camera bug (http://www.chiefdelphi.com/forums/showthread.php?t=102309)

Method 08-02-2012 20:17

Camera bug
 
z:
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("10.16.71.11");
//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

public:
RobotDemo(void):
stick(1) // as they are declared above.
{
GetWatchdog().Kill();
binImg = image.ThresholdHSL(0, 250, 30, 200, 130, 270);
//HSL values (MUST BE FOUND BY EXPERIMENT)
camera.WriteMaxFPS(30);
//FPS
camera.WriteBrightness(30);
//
camera.WriteWhiteBalance(AxisCamera::kWhiteBalance _Hold);
//white balance -- set manually via internet connection w/hold
camera.WriteResolution(AxisCamera::kResolution_320 x240);
//resolution
camera.WriteColorLevel(100);
//low color
camera.WriteCompression(30);
//lower easier on CRIO and harder on cam
}
void Autonomous(void)
{
GetWatchdog().Kill();
}
void OperatorControl(void)
{
GetWatchdog().Kill();
while (IsOperatorControl())
{
camera.GetImage(&image);
vector<ParticleAnalysisReport>* particles = binImg->GetOrderedParticleAnalysisReports();
ParticleAnalysisReport& par = (*particles)[1];
driverOut->Clear();
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
}
driverOut->UpdateLCD();
}
}
};

START_ROBOT_CLASS(RobotDemo);

mikets 08-02-2012 20:44

Re: Camera bug
 
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.
http://firstforge.wpi.edu/sf/frs/do/...2_update_for_c

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

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).
Code:

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


Method 08-02-2012 22:01

Re: Camera bug
 
This example makes life 1000* easier. thanks for pointing the way

Method 08-02-2012 23:20

Re: Camera bug
 
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?

mikets 09-02-2012 00:45

Re: Camera bug
 
AxisCamera::GetImage has three overloads. One takes a ColorImage* as parameter.
Code:

int AxisCamera::GetImage(ColorImage* image)

Method 09-02-2012 00:46

Re: Camera bug
 
nvm got it!



ColorImage image(IMAQ_IMAGE_RGB);
camera.GetImage(&image);
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->PrintfLine(DriverStationLCD::kUser_Line2, "Target Select, numTargets: %n", (int)particles->size());
driverOut->UpdateLCD();


delete particles;
delete filteredImage;
delete convexHullImage;
delete bigObjectsImage;
delete thresholdImage;
delete &image;

Method 09-02-2012 04:22

Re: Camera bug
 
1 Attachment(s)
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

Method 09-02-2012 22:30

Re: Camera bug
 
tested today and messed with it more. everything works now. thanks

duane 12-02-2012 22:34

Re: Camera bug
 
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.

...Duane

bob.wolff68 14-02-2012 02:05

Re: Camera bug
 
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.

:-)

bob

Method 14-02-2012 20:58

Re: Camera bug
 
1 Attachment(s)
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)
help?

The three files are rather long so I attached them.

thanks! : |)


All times are GMT -5. The time now is 13:05.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi