View Single Post
  #1   Spotlight this post!  
Unread 19-03-2012, 18:18
thecakeisalie's Avatar
thecakeisalie thecakeisalie is offline
Registered User
FRC #0293
 
Join Date: Mar 2012
Location: Pennington
Posts: 37
thecakeisalie is an unknown quantity at this point
Vision Code question.

Having finished writing the vision code, I tested our vision code. The only problem is that it did not seem to work.
if you can pinpoint our problem, it would be very helpful. This is my first year coding camera code in c++, so... i expect many things to go wrong

the vision.h:
Code:
#ifndef VISION_H
#define VISION_H
#include "WPILib.h"

class Vision {
private:
	AxisCamera * camera;

public:
	Vision();
	int Height();
	int Center_Mass();
	double GetDistance(int h);
};

#endif
the vision.cpp:
Code:
#include "../Robotmap.h"
#include "Vision.h"
#include <math.h>
#define PI 3.14159265


Vision::Vision() {
camera ->GetInstance("10.02.93.15");
}
int Vision::Center_Mass()
{
	ParticleFilterCriteria2 criteria[] = {
						{IMAQ_MT_BOUNDING_RECT_WIDTH, 30, 400, false, false},
						{IMAQ_MT_BOUNDING_RECT_HEIGHT, 40, 400, false, false}
				};
			ColorImage *image = camera->GetImage();
			Threshold threshold(10, 255, 200, 255, 150, 255);
			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> *reports = filteredImage->GetOrderedParticleAnalysisReports();  // get the results				

			ParticleAnalysisReport *r = &(reports->at(1));
			int center_mass_x =  r->center_mass_x; // int, in pixels

			
			delete reports;
			delete filteredImage;
			delete convexHullImage;
			delete bigObjectsImage;
			delete thresholdImage;
			delete image;
			
			return center_mass_x;
}
and the aiming part:
Code:
	while (vision->Center_Mass() <159 || vision->Center_Mass() > 161){
		while (vision->Center_Mass() < 159){
			turret->DriveMotor(0.1);
			if (vision->Center_Mass() > 159) break;
		}
		while (vision->Center_Mass() > 161){
			turret->DriveMotor(-0.1);
			if (vision->Center_Mass() < 161) break;
		}
	}

Last edited by thecakeisalie : 19-03-2012 at 18:53.
Reply With Quote