WPILib 2012
WPILibRoboticsLibraryforFRC
Vision2009/VisionAPI.h
00001 /********************************************************************************
00002 *  Project              : FIRST Motor Controller
00003 *  File Name            : VisionAPI.h          
00004 *  Contributors         : ELF, JDG, ARK, EMF
00005 *  Creation Date        : June 22, 2008
00006 *  Revision History     : Source code & revision history maintained at sourceforge.WPI.edu    
00007 *  File Description     : Globally defined values for the FIRST Vision API
00008 * 
00009 *  API: Because nivision.h uses C++ style comments, any file including this
00010 *  must be a .cpp (not .c).
00011 */
00012 /*----------------------------------------------------------------------------*/
00013 /*        Copyright (c) FIRST 2008.  All Rights Reserved.                     */
00014 /*  Open Source Software - may be modified and shared by FRC teams. The code  */
00015 /*  must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
00016 /*----------------------------------------------------------------------------*/
00017 
00018 #ifndef __VISIONAPI_H__
00019 #define __VISIONAPI_H__
00020 
00021 #include "nivision.h" 
00022 
00023 /*   Constants */
00024 
00025 #define DEFAULT_BORDER_SIZE                             3               //VisionAPI.frcCreateImage
00026 #define DEFAULT_SATURATION_THRESHOLD    40              //TrackAPI.FindColor
00027 
00028 /*   Forward Declare Data Structures */
00029 typedef struct FindEdgeOptions_struct FindEdgeOptions;
00030 typedef struct CircularEdgeReport_struct CircularEdgeReport;
00031 
00032 /*   Data Structures */
00033 
00035 typedef struct ParticleAnalysisReport_struct {
00036         int     imageHeight;
00037         int     imageWidth;
00038         double  imageTimestamp;                         
00039         int             particleIndex;                          // the particle index analyzed
00040         /* X-coordinate of the point representing the average position of the 
00041          * total particle mass, assuming every point in the particle has a constant density */
00042         int     center_mass_x;                          // MeasurementType: IMAQ_MT_CENTER_OF_MASS_X 
00043         /* Y-coordinate of the point representing the average position of the 
00044          * total particle mass, assuming every point in the particle has a constant density */
00045         int     center_mass_y;                          // MeasurementType: IMAQ_MT_CENTER_OF_MASS_Y 
00046         double  center_mass_x_normalized;       //Center of mass x value normalized to -1.0 to +1.0 range
00047         double  center_mass_y_normalized;       //Center of mass y value normalized to -1.0 to +1.0 range
00048         /* Area of the particle */
00049         double  particleArea;                           // MeasurementType: IMAQ_MT_AREA
00050         /* Bounding Rectangle */
00051         Rect    boundingRect;                           // left/top/width/height
00052         /* Percentage of the particle Area covering the Image Area. */
00053         double  particleToImagePercent;         // MeasurementType: IMAQ_MT_AREA_BY_IMAGE_AREA
00054         /* Percentage of the particle Area in relation to its Particle and Holes Area */
00055         double  particleQuality;                        // MeasurementType: IMAQ_MT_AREA_BY_PARTICLE_AND_HOLES_AREA
00056 } ParticleAnalysisReport;
00057 
00059 typedef struct ColorReport_struct {
00060         int             numberParticlesFound;                           // Number of particles found for this color
00061         int     largestParticleNumber;                          // The particle index of the largest particle
00062         /* Color information */
00063         float   particleHueMax;                         // HistogramReport: hue max
00064         float   particleHueMin;                         // HistogramReport: hue max
00065         float   particleHueMean;                        // HistogramReport: hue mean
00066         float   particleSatMax;                         // HistogramReport: saturation max
00067         float   particleSatMin;                         // HistogramReport: saturation max
00068         float   particleSatMean;                        // HistogramReport: saturation mean
00069         float   particleLumMax;                         // HistogramReport: luminance max
00070         float   particleLumMin;                         // HistogramReport: luminance  max
00071         float   particleLumMean;                        // HistogramReport: luminance mean
00072 } ColorReport;
00073 
00074 
00075 /*   Image Management functions */
00076 
00077 /* Create: calls imaqCreateImage. Border size is set to some default value */
00078 Image* frcCreateImage( ImageType type );
00079 
00080 /* Dispose: calls imaqDispose */
00081 int frcDispose( void* object );
00082 int frcDispose( const char* filename, ... ) ;
00083 
00084 /* Copy: calls imaqDuplicateImage */
00085 int frcCopyImage( Image* dest, const Image* source );
00086 
00087 /* Image Extraction: Crop: calls imaqScale */
00088 int frcCrop( Image* dest, const Image* source, Rect rect );
00089 
00090 /* Image Extraction: Scale: calls imaqScale.  Scales entire image */
00091 int frcScale(Image* dest, const Image* source, int xScale, int yScale, ScalingMode scaleMode );
00092 
00093 /* Read Image : calls imaqReadFile */
00094 int frcReadImage( Image* image, const char* fileName );
00095 /* Write Image : calls imaqWriteFile */
00096 int frcWriteImage( const Image* image, const char* fileName);
00097 
00098 /*   Measure Intensity functions */
00099 
00100 /* Histogram: calls imaqHistogram */
00101 HistogramReport* frcHistogram( const Image* image, int numClasses, float min, float max, Rect rect );
00102 /* Color Histogram: calls imaqColorHistogram2 */
00103 ColorHistogramReport* frcColorHistogram(const Image* image, int numClasses, ColorMode mode, Image* mask);
00104 
00105 /* Get Pixel Value: calls imaqGetPixel */
00106 int frcGetPixelValue( const Image* image, Point pixel, PixelValue* value );
00107 
00108 /*   Particle Analysis functions */
00109 
00110 /* Particle Filter: calls imaqParticleFilter3 */
00111 int frcParticleFilter(Image* dest, Image* source, const ParticleFilterCriteria2* criteria, 
00112                 int criteriaCount, const ParticleFilterOptions* options, Rect rect, int* numParticles);
00113 int frcParticleFilter(Image* dest, Image* source, const ParticleFilterCriteria2* criteria, 
00114                 int criteriaCount, const ParticleFilterOptions* options, int* numParticles);
00115 /* Morphology: calls imaqMorphology */
00116 int frcMorphology(Image* dest, Image* source, MorphologyMethod method);
00117 int frcMorphology(Image* dest, Image* source, MorphologyMethod method, const StructuringElement* structuringElement);
00118 /* Reject Border: calls imaqRejectBorder */
00119 int frcRejectBorder(Image* dest, Image* source);
00120 int frcRejectBorder(Image* dest, Image* source, int connectivity8);
00121 /* Count Particles: calls imaqCountParticles */
00122 int frcCountParticles(Image* image, int* numParticles);
00123 /* Particle Analysis Report: calls imaqMeasureParticle */
00124 int frcParticleAnalysis(Image* image, int particleNumber, ParticleAnalysisReport* par);
00125 
00126 /*   Image Enhancement functions */
00127 
00128 /* Equalize: calls imaqEqualize */
00129 int frcEqualize(Image* dest, const Image* source, float min, float max);
00130 int frcEqualize(Image* dest, const Image* source, float min, float max, const Image* mask);
00131 
00132 /* Color Equalize: calls imaqColorEqualize */
00133 int frcColorEqualize(Image* dest, const Image* source);
00134 int frcColorEqualize(Image* dest, const Image* source, int colorEqualization);
00135 
00136 /*   Image Thresholding & Conversion functions */
00137 
00138 /* Smart Threshold: calls imaqLocalThreshold */
00139 int frcSmartThreshold(Image* dest, const Image* source, unsigned int windowWidth, unsigned int windowHeight, 
00140                 LocalThresholdMethod method, double deviationWeight, ObjectType type);
00141 int frcSmartThreshold(Image* dest, const Image* source, unsigned int windowWidth, unsigned int windowHeight, 
00142                 LocalThresholdMethod method, double deviationWeight, ObjectType type, float replaceValue);
00143 
00144 /* Simple Threshold: calls imaqThreshold */
00145 int frcSimpleThreshold(Image* dest, const Image* source, float rangeMin, float rangeMax, float newValue);
00146 int frcSimpleThreshold(Image* dest, const Image* source, float rangeMin, float rangeMax);
00147 
00148 /* Color/Hue Threshold: calls imaqColorThreshold */
00149 int frcColorThreshold(Image* dest, const Image* source, ColorMode mode, 
00150                 const Range* plane1Range, const Range* plane2Range, const Range* plane3Range);
00151 int frcColorThreshold(Image* dest, const Image* source, int replaceValue, ColorMode mode, 
00152                 const Range* plane1Range, const Range* plane2Range, const Range* plane3Range);
00153 int frcHueThreshold(Image* dest, const Image* source, const Range* hueRange);
00154 int frcHueThreshold(Image* dest, const Image* source, const Range* hueRange, int minSaturation);
00155 
00156 /* Extract ColorHue Plane: calls imaqExtractColorPlanes */
00157 int frcExtractColorPlanes(const Image* image, ColorMode mode, Image* plane1, Image* plane2, Image* plane3);
00158 int frcExtractHuePlane(const Image* image, Image* huePlane);
00159 int frcExtractHuePlane(const Image* image, Image* huePlane, int minSaturation);
00160 
00161 #endif
00162 
00163 
 All Classes Functions Variables