Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2014. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ |
| 5 | /*----------------------------------------------------------------------------*/ |
| 6 | |
| 7 | #pragma once |
| 8 | |
| 9 | #include "nivision.h" |
| 10 | |
| 11 | /* Constants */ |
| 12 | |
| 13 | #define DEFAULT_BORDER_SIZE 3 // VisionAPI.frcCreateImage |
| 14 | #define DEFAULT_SATURATION_THRESHOLD 40 // TrackAPI.FindColor |
| 15 | |
| 16 | /* Forward Declare Data Structures */ |
| 17 | typedef struct FindEdgeOptions_struct FindEdgeOptions; |
| 18 | typedef struct CircularEdgeReport_struct CircularEdgeReport; |
| 19 | |
| 20 | /* Data Structures */ |
| 21 | |
| 22 | /** frcParticleAnalysis returns this structure */ |
| 23 | typedef struct ParticleAnalysisReport_struct { |
| 24 | int imageHeight; |
| 25 | int imageWidth; |
| 26 | double imageTimestamp; |
| 27 | int particleIndex; // the particle index analyzed |
| 28 | /* X-coordinate of the point representing the average position of the |
| 29 | * total particle mass, assuming every point in the particle has a constant |
| 30 | * density */ |
| 31 | int center_mass_x; // MeasurementType: IMAQ_MT_CENTER_OF_MASS_X |
| 32 | /* Y-coordinate of the point representing the average position of the |
| 33 | * total particle mass, assuming every point in the particle has a constant |
| 34 | * density */ |
| 35 | int center_mass_y; // MeasurementType: IMAQ_MT_CENTER_OF_MASS_Y |
| 36 | double center_mass_x_normalized; // Center of mass x value normalized to -1.0 |
| 37 | // to +1.0 range |
| 38 | double center_mass_y_normalized; // Center of mass y value normalized to -1.0 |
| 39 | // to +1.0 range |
| 40 | /* Area of the particle */ |
| 41 | double particleArea; // MeasurementType: IMAQ_MT_AREA |
| 42 | /* Bounding Rectangle */ |
| 43 | Rect boundingRect; // left/top/width/height |
| 44 | /* Percentage of the particle Area covering the Image Area. */ |
| 45 | double particleToImagePercent; // MeasurementType: IMAQ_MT_AREA_BY_IMAGE_AREA |
| 46 | /* Percentage of the particle Area in relation to its Particle and Holes Area |
| 47 | */ |
| 48 | double particleQuality; // MeasurementType: |
| 49 | // IMAQ_MT_AREA_BY_PARTICLE_AND_HOLES_AREA |
| 50 | } ParticleAnalysisReport; |
| 51 | |
| 52 | /** Tracking functions return this structure */ |
| 53 | typedef struct ColorReport_struct { |
| 54 | int numberParticlesFound; // Number of particles found for this color |
| 55 | int largestParticleNumber; // The particle index of the largest particle |
| 56 | /* Color information */ |
| 57 | float particleHueMax; // HistogramReport: hue max |
| 58 | float particleHueMin; // HistogramReport: hue max |
| 59 | float particleHueMean; // HistogramReport: hue mean |
| 60 | float particleSatMax; // HistogramReport: saturation max |
| 61 | float particleSatMin; // HistogramReport: saturation max |
| 62 | float particleSatMean; // HistogramReport: saturation mean |
| 63 | float particleLumMax; // HistogramReport: luminance max |
| 64 | float particleLumMin; // HistogramReport: luminance max |
| 65 | float particleLumMean; // HistogramReport: luminance mean |
| 66 | } ColorReport; |
| 67 | |
| 68 | /* Image Management functions */ |
| 69 | |
| 70 | /* Create: calls imaqCreateImage. Border size is set to some default value */ |
| 71 | Image* frcCreateImage(ImageType type); |
| 72 | |
| 73 | /* Dispose: calls imaqDispose */ |
| 74 | int frcDispose(void* object); |
| 75 | int frcDispose(const char* filename, ...); |
| 76 | |
| 77 | /* Copy: calls imaqDuplicateImage */ |
| 78 | int frcCopyImage(Image* dest, const Image* source); |
| 79 | |
| 80 | /* Image Extraction: Crop: calls imaqScale */ |
| 81 | int frcCrop(Image* dest, const Image* source, Rect rect); |
| 82 | |
| 83 | /* Image Extraction: Scale: calls imaqScale. Scales entire image */ |
| 84 | int frcScale(Image* dest, const Image* source, int xScale, int yScale, |
| 85 | ScalingMode scaleMode); |
| 86 | |
| 87 | /* Read Image : calls imaqReadFile */ |
| 88 | int frcReadImage(Image* image, const char* fileName); |
| 89 | /* Write Image : calls imaqWriteFile */ |
| 90 | int frcWriteImage(const Image* image, const char* fileName); |
| 91 | |
| 92 | /* Measure Intensity functions */ |
| 93 | |
| 94 | /* Histogram: calls imaqHistogram */ |
| 95 | HistogramReport* frcHistogram(const Image* image, int numClasses, float min, |
| 96 | float max, Rect rect); |
| 97 | /* Color Histogram: calls imaqColorHistogram2 */ |
| 98 | ColorHistogramReport* frcColorHistogram(const Image* image, int numClasses, |
| 99 | ColorMode mode, Image* mask); |
| 100 | |
| 101 | /* Get Pixel Value: calls imaqGetPixel */ |
| 102 | int frcGetPixelValue(const Image* image, Point pixel, PixelValue* value); |
| 103 | |
| 104 | /* Particle Analysis functions */ |
| 105 | |
| 106 | /* Particle Filter: calls imaqParticleFilter3 */ |
| 107 | int frcParticleFilter(Image* dest, Image* source, |
| 108 | const ParticleFilterCriteria2* criteria, |
| 109 | int criteriaCount, const ParticleFilterOptions* options, |
| 110 | Rect rect, int* numParticles); |
| 111 | int frcParticleFilter(Image* dest, Image* source, |
| 112 | const ParticleFilterCriteria2* criteria, |
| 113 | int criteriaCount, const ParticleFilterOptions* options, |
| 114 | int* numParticles); |
| 115 | /* Morphology: calls imaqMorphology */ |
| 116 | int frcMorphology(Image* dest, Image* source, MorphologyMethod method); |
| 117 | int frcMorphology(Image* dest, Image* source, MorphologyMethod method, |
| 118 | const StructuringElement* structuringElement); |
| 119 | /* Reject Border: calls imaqRejectBorder */ |
| 120 | int frcRejectBorder(Image* dest, Image* source); |
| 121 | int frcRejectBorder(Image* dest, Image* source, int connectivity8); |
| 122 | /* Count Particles: calls imaqCountParticles */ |
| 123 | int frcCountParticles(Image* image, int* numParticles); |
| 124 | /* Particle Analysis Report: calls imaqMeasureParticle */ |
| 125 | int frcParticleAnalysis(Image* image, int particleNumber, |
| 126 | ParticleAnalysisReport* par); |
| 127 | |
| 128 | /* Image Enhancement functions */ |
| 129 | |
| 130 | /* Equalize: calls imaqEqualize */ |
| 131 | int frcEqualize(Image* dest, const Image* source, float min, float max); |
| 132 | int frcEqualize(Image* dest, const Image* source, float min, float max, |
| 133 | const Image* mask); |
| 134 | |
| 135 | /* Color Equalize: calls imaqColorEqualize */ |
| 136 | int frcColorEqualize(Image* dest, const Image* source); |
| 137 | int frcColorEqualize(Image* dest, const Image* source, int colorEqualization); |
| 138 | |
| 139 | /* Image Thresholding & Conversion functions */ |
| 140 | |
| 141 | /* Smart Threshold: calls imaqLocalThreshold */ |
| 142 | int frcSmartThreshold(Image* dest, const Image* source, |
| 143 | unsigned int windowWidth, unsigned int windowHeight, |
| 144 | LocalThresholdMethod method, double deviationWeight, |
| 145 | ObjectType type); |
| 146 | int frcSmartThreshold(Image* dest, const Image* source, |
| 147 | unsigned int windowWidth, unsigned int windowHeight, |
| 148 | LocalThresholdMethod method, double deviationWeight, |
| 149 | ObjectType type, float replaceValue); |
| 150 | |
| 151 | /* Simple Threshold: calls imaqThreshold */ |
| 152 | int frcSimpleThreshold(Image* dest, const Image* source, float rangeMin, |
| 153 | float rangeMax, float newValue); |
| 154 | int frcSimpleThreshold(Image* dest, const Image* source, float rangeMin, |
| 155 | float rangeMax); |
| 156 | |
| 157 | /* Color/Hue Threshold: calls imaqColorThreshold */ |
| 158 | int frcColorThreshold(Image* dest, const Image* source, ColorMode mode, |
| 159 | const Range* plane1Range, const Range* plane2Range, |
| 160 | const Range* plane3Range); |
| 161 | int frcColorThreshold(Image* dest, const Image* source, int replaceValue, |
| 162 | ColorMode mode, const Range* plane1Range, |
| 163 | const Range* plane2Range, const Range* plane3Range); |
| 164 | int frcHueThreshold(Image* dest, const Image* source, const Range* hueRange); |
| 165 | int frcHueThreshold(Image* dest, const Image* source, const Range* hueRange, |
| 166 | int minSaturation); |
| 167 | |
| 168 | /* Extract ColorHue Plane: calls imaqExtractColorPlanes */ |
| 169 | int frcExtractColorPlanes(const Image* image, ColorMode mode, Image* plane1, |
| 170 | Image* plane2, Image* plane3); |
| 171 | int frcExtractHuePlane(const Image* image, Image* huePlane); |
| 172 | int frcExtractHuePlane(const Image* image, Image* huePlane, int minSaturation); |