Go to Post I'm hoping for a JVN action figure this year! - marshall [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 13-02-2012, 03:23
Method's Avatar
Method Method is offline
Registered User
no team
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Ca
Posts: 38
Method is an unknown quantity at this point
simple camera feed and LCD output

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


Code:
#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::kWhiteBalance_Hold);
		eyeOfSauron.WriteResolution(AxisCamera::kResolution_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);
Reply With Quote
  #2   Spotlight this post!  
Unread 13-02-2012, 06:55
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: simple camera feed and LCD output

I did not look at your code very carefully but one thing jumped out:
Code:
 void CamAnOut (void)
	{
		    Threshold threshold(RH, RL, GH, GL, BH, BL);
I believe you have reversed the High and Low numbers. It should be:
Code:
 void CamAnOut (void)
	{
		        Threshold threshold(RL, RH, GL, GH, BL, BH);
__________________
Reply With Quote
  #3   Spotlight this post!  
Unread 13-02-2012, 14:20
Method's Avatar
Method Method is offline
Registered User
no team
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Ca
Posts: 38
Method is an unknown quantity at this point
Re: simple camera feed and LCD output

oh yeah-> retyped that, thanks
Reply With Quote
  #4   Spotlight this post!  
Unread 13-02-2012, 22:47
Method's Avatar
Method Method is offline
Registered User
no team
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Ca
Posts: 38
Method is an unknown quantity at this point
Re: simple camera feed and LCD output

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*)'
Reply With Quote
  #5   Spotlight this post!  
Unread 13-02-2012, 23:52
Method's Avatar
Method Method is offline
Registered User
no team
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Ca
Posts: 38
Method is an unknown quantity at this point
Re: simple camera feed and LCD output

//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);
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 03:00.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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