Go to Post A good robot can score a lot of points. A great robot can do it when the other alliance does everything they can to stop it. - Rick TYler [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 16-02-2012, 04:21
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
general image tracking commands

Hello- simple playing around with wrappers
I have two errors highlighted in red and would appreciate a nudge in the right direction(they're different instances of the same error).

Also, I'd love some more simple commands examples like this: particularly the one which uses a particle filter to add or remove particles based on %Area/(Particle & Holes' Area) which is in the NI Vision Assistant.

One last:There are many references to reading and writing image files. Is this only necessary in Java or when making an example which uses pictures from the a folder, e.g., 'vision images' in the project?

Thankyou for any help!

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

#define BS 1.0f
#define CT 1.0f
#define GA 1.0f

static AxisCamera &eyeOfSauron = AxisCamera::GetInstance("255.255.255.255");
DriverStationLCD* driverOut = DriverStationLCD::GetInstance();

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);
		eyeOfSauron.WriteMaxFPS(5);
		//lower easier on CRIO and harder on cam
	}
	
	void Autonomous(void)
	{
		GetWatchdog().Kill();		
		while (IsAutonomous() && IsEnabled()) 
		{
			GetWatchdog().Kill();
			CamAnOut();
		}
	}
	void OperatorControl(void)
	{
		GetWatchdog().Kill();
		while (IsOperatorControl() && IsEnabled())
		{
			GetWatchdog().Kill();
			CamAnOut();
		}
	}
	void CamAnOut (void)
	{
//used to remove red, green or blue particles out of range
		Threshold threshold(RL, RH, GL, GH, BL, BH);

//used to remove particles out of criteria
		ParticleFilterCriteria2 criteria[] = {
											{IMAQ_MT_BOUNDING_RECT_WIDTH, 10, 200, false, false},
											{IMAQ_MT_BOUNDING_RECT_HEIGHT, 10, 200, false, false}};
				
		ColorImage image(IMAQ_IMAGE_RGB);
		//make image
		
		if (eyeOfSauron.IsFreshImage())//if latest from cam not recieved
		{
			eyeOfSauron.GetImage(&image);
			//store camera feed to image
			//out new im # ()  ---  add a big number to it
		}
		else
		{
			//out old im  ---  sub a small number from it
			//play till refreshes at 0 for awesomeness XD
			


			/*	AxisCamera::GetImage returns ColorImage* ... (or HSLImage* due to inheritance)
				ColorImage::ThresholdHSL returns BinaryImage*
				BinaryImage:: has the particle analysis routines
			*/	
			
			
//changes brightness, contrast and gamma
			Image* BCG = image.GetImaqImage();
			delete ℑ
			BCGOptions bcg;
			bcg.brightness = BS;
			bcg.contrast = CT;
			bcg.gamma = GA;
			imaqBCGTransform(BCG, BCG, &bcg, NULL);
			
			HSLImage *thresholdLUM = BCG->ThresholdHSL(1,2,1,2,1,2);
//would remove out of range HSL particles
			delete &BCG;

//separates luminance
			MonoImage* luminance = thresholdLUM->GetLuminancePlane();
			 delete thresholdLUM;
			imaqDispose(BCG);
			image.ReplaceRedPlane(luminance);
			image.ReplaceGreenPlane(luminance);
			image.ReplaceBluePlane(luminance);
			
//not with HSL image and threshold-removes out of range RGB	BinaryImage *thresholdImage = BCG->ThresholdRGB(threshold);
			//pixel range		

//change img type
			BinaryImage *binImg = luminance;
				delete luminance;
//complete particles
			 imaqConvexHull(binImg->GetImaqImage(),binImg->GetImaqImage(),1);
	
			BinaryImage *bigObjectsImage = binImg->RemoveSmallObjects(false, 2);
			// remove small objects (noise)
			delete binImg;
			
			BinaryImage *convexHullImage = bigObjectsImage->ConvexHull(false);
			// fill in partial and full rectangles
			delete bigObjectsImage;
			
			BinaryImage *filteredImage = convexHullImage->ParticleFilter(criteria, 2);
			// find the rectangles by above cruteria
			delete convexHullImage;
			
			vector<ParticleAnalysisReport> *particles = filteredImage->GetOrderedParticleAnalysisReports();
			// get the results
			delete filteredImage;
			
			
			ParticleAnalysisReport *high = &(particles)->at(1);
			ParticleAnalysisReport *particle = &(particles)->at(2);
			for (unsigned int i = 1; i <= particles->size(); i++)
			{
				particle = &(particles)->at(i);
							
				//target select
				if(particle->center_mass_y_normalized > high->center_mass_y_normalized) 
				{
					high = &(particles)->at(i);
				}
				delete particle;
			}
			
			//LCD output
			driverOut->UpdateLCD();
			
	//			delete reports;
			
			delete particles;
			delete high;
			
		}
		
	}
};

START_ROBOT_CLASS(VisionSample2012);
Reply With Quote
  #2   Spotlight this post!  
Unread 16-02-2012, 17:11
frdrake frdrake is offline
Registered User
FRC #0233
 
Join Date: Feb 2012
Location: Melbourne
Posts: 23
frdrake is on a distinguished road
Re: general image tracking commands

I had a problem with my BinaryImage file because they released a new update for WindRiver on Feb. 4 with additional functions in this class. Have you already gotten that update?
Reply With Quote
  #3   Spotlight this post!  
Unread 16-02-2012, 20:53
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: general image tracking commands

yes, i have, but my main point of interest is how to do the %Area/(Particle & Holes' Area) criteria
Reply With Quote
  #4   Spotlight this post!  
Unread 16-02-2012, 21:33
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: general image tracking commands

bool AxisCamera::IsFreshImage ( )
Return true if the latest image from the camera has not been retrieved by calling GetImage() yet.

Returns:
true if the image has not been retrieved yet.


Im having trouble believing this.. can someone confirm?
Reply With Quote
  #5   Spotlight this post!  
Unread 17-02-2012, 01:59
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: general image tracking commands

Yes, according to the source code of the WPILib, IsFreshImage() returns the member variable m_freshImage. This variable is set by the UpdatePublicImageFromCamera() function in the camera task and cleared when you call GetImage(). So yes, once an image is available, as long as you haven't retrieved it by calling GetImage, it will remain "fresh".
__________________
Reply With Quote
  #6   Spotlight this post!  
Unread 17-02-2012, 02:10
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: general image tracking commands

Thankyou! XD
Reply With Quote
  #7   Spotlight this post!  
Unread 17-02-2012, 02:21
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: general image tracking commands

Quote:
Originally Posted by mikets View Post
Yes, according to the source code of the WPILib, IsFreshImage() returns the member variable m_freshImage. This variable is set by the UpdatePublicImageFromCamera() function in the camera task and cleared when you call GetImage(). So yes, once an image is available, as long as you haven't retrieved it by calling GetImage, it will remain "fresh".
BTW, it is possible that you haven't retrieved the image yet but another image is available so it will update the image with the new one. In other words, you don't have to worry about the image being stale.
__________________
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:04.

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