public: struct RangeResult * GetRange(IplImage * imgRange,IplImage * imgDst); LaserRange(); virtual ~LaserRange(); private: unsigned int maxW; unsigned int maxH; unsigned int MaxPixel; RangeResult * strctResult; // Values used for calculating range from captured image data const double gain; // Gain Constant used for converting pixel offset to angle in radians const double offset;// Offset Constant const double h_cm; // Distance between center of camera and laser unsigned int pixels_from_center; // Brightest pixel location from center void Preprocess(void * img,IplImage * imgTemp); ;cpp文件: LaserRange::LaserRange():gain(0.0030354),offset(0),h_cm(4.542)
maxW=0; maxH=0; MaxPixel=0; pixels_from_center=0; // Brightest pixel location from center strctResult=new RangeResult; strctResult->maxCol=0; strctResult->maxRow=0; strctResult->maxPixel=0; strctResult->Range=0.0; LaserRange::~LaserRange()
if(NULL!=strctResult) delete strctResult; struct RangeResult * LaserRange::GetRange(IplImage * imgRange,IplImage * imgDst) if(NULL==imgRange) return strctResult; Preprocess(imgRange,imgDst); pixels_from_center = abs(120-maxH);// Calculate range in cm based on bright pixel location, and setup specific constants strctResult->Range= h_cm/tan(pixels_from_center * gain + offset); strctResult->PixfromCent=pixels_from_center; strctResult->maxCol=maxW; strctResult->maxRow=maxH; strctResult->maxPixel=MaxPixel; //strctResult->Range=0.0; return strctResult;