|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
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); |
|
#2
|
||||
|
||||
|
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); Code:
driverOut->PrintfLine(DriverStationLCD::kUser_Line1, "Z: %d", particles->size());//output num targets driverOut->PrintfLine(DriverStationLCD::kUser_Line2, "sumtin %d", par.center_mass_y); |
|
#3
|
||||
|
||||
|
Re: Camera bug
This example makes life 1000* easier. thanks for pointing the way
|
|
#4
|
||||
|
||||
|
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? |
|
#5
|
||||
|
||||
|
Re: Camera bug
AxisCamera::GetImage has three overloads. One takes a ColorImage* as parameter.
Code:
int AxisCamera::GetImage(ColorImage* image) |
|
#6
|
||||
|
||||
|
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 |
|
#7
|
||||
|
||||
|
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 |
|
#8
|
||||
|
||||
|
Re: Camera bug
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! : |) |
|
#9
|
||||
|
||||
|
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 ℑ |
|
#10
|
||||
|
||||
|
Re: Camera bug
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
|
|
#11
|
||||
|
||||
|
Re: Camera bug
tested today and messed with it more. everything works now. thanks
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|