View Single Post
  #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