WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
VisionAPI.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2014-2016. 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 the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include "nivision.h"
11 
12 /* Constants */
13 
14 #define DEFAULT_BORDER_SIZE 3 // VisionAPI.frcCreateImage
15 #define DEFAULT_SATURATION_THRESHOLD 40 // TrackAPI.FindColor
16 
17 /* Forward Declare Data Structures */
18 typedef struct FindEdgeOptions_struct FindEdgeOptions;
19 typedef struct CircularEdgeReport_struct CircularEdgeReport;
20 
21 /* Data Structures */
22 
25  int imageHeight;
26  int imageWidth;
27  double imageTimestamp;
28  int particleIndex; // the particle index analyzed
29  /* X-coordinate of the point representing the average position of the
30  * total particle mass, assuming every point in the particle has a constant
31  * density */
32  int center_mass_x; // MeasurementType: IMAQ_MT_CENTER_OF_MASS_X
33  /* Y-coordinate of the point representing the average position of the
34  * total particle mass, assuming every point in the particle has a constant
35  * density */
36  int center_mass_y; // MeasurementType: IMAQ_MT_CENTER_OF_MASS_Y
37  double center_mass_x_normalized; // Center of mass x value normalized to -1.0
38  // to +1.0 range
39  double center_mass_y_normalized; // Center of mass y value normalized to -1.0
40  // to +1.0 range
41  /* Area of the particle */
42  double particleArea; // MeasurementType: IMAQ_MT_AREA
43  /* Bounding Rectangle */
44  Rect boundingRect; // left/top/width/height
45  /* Percentage of the particle Area covering the Image Area. */
46  double particleToImagePercent; // MeasurementType: IMAQ_MT_AREA_BY_IMAGE_AREA
47  /* Percentage of the particle Area in relation to its Particle and Holes Area
48  */
49  double particleQuality; // MeasurementType:
50  // IMAQ_MT_AREA_BY_PARTICLE_AND_HOLES_AREA
52 
54 typedef struct ColorReport_struct {
55  int numberParticlesFound; // Number of particles found for this color
56  int largestParticleNumber; // The particle index of the largest particle
57  /* Color information */
58  float particleHueMax; // HistogramReport: hue max
59  float particleHueMin; // HistogramReport: hue max
60  float particleHueMean; // HistogramReport: hue mean
61  float particleSatMax; // HistogramReport: saturation max
62  float particleSatMin; // HistogramReport: saturation max
63  float particleSatMean; // HistogramReport: saturation mean
64  float particleLumMax; // HistogramReport: luminance max
65  float particleLumMin; // HistogramReport: luminance max
66  float particleLumMean; // HistogramReport: luminance mean
67 } ColorReport;
68 
69 /* Image Management functions */
70 
71 /* Create: calls imaqCreateImage. Border size is set to some default value */
72 Image* frcCreateImage(ImageType type);
73 
74 /* Dispose: calls imaqDispose */
75 int frcDispose(void* object);
76 int frcDispose(const char* filename, ...);
77 
78 /* Copy: calls imaqDuplicateImage */
79 int frcCopyImage(Image* dest, const Image* source);
80 
81 /* Image Extraction: Crop: calls imaqScale */
82 int frcCrop(Image* dest, const Image* source, Rect rect);
83 
84 /* Image Extraction: Scale: calls imaqScale. Scales entire image */
85 int frcScale(Image* dest, const Image* source, int xScale, int yScale,
86  ScalingMode scaleMode);
87 
88 /* Read Image : calls imaqReadFile */
89 int frcReadImage(Image* image, const char* fileName);
90 /* Write Image : calls imaqWriteFile */
91 int frcWriteImage(const Image* image, const char* fileName);
92 
93 /* Measure Intensity functions */
94 
95 /* Histogram: calls imaqHistogram */
96 HistogramReport* frcHistogram(const Image* image, int numClasses, float min,
97  float max, Rect rect);
98 /* Color Histogram: calls imaqColorHistogram2 */
99 ColorHistogramReport* frcColorHistogram(const Image* image, int numClasses,
100  ColorMode mode, Image* mask);
101 
102 /* Get Pixel Value: calls imaqGetPixel */
103 int frcGetPixelValue(const Image* image, Point pixel, PixelValue* value);
104 
105 /* Particle Analysis functions */
106 
107 /* Particle Filter: calls imaqParticleFilter3 */
108 int frcParticleFilter(Image* dest, Image* source,
109  const ParticleFilterCriteria2* criteria,
110  int criteriaCount, const ParticleFilterOptions* options,
111  Rect rect, int* numParticles);
112 int frcParticleFilter(Image* dest, Image* source,
113  const ParticleFilterCriteria2* criteria,
114  int criteriaCount, const ParticleFilterOptions* options,
115  int* numParticles);
116 /* Morphology: calls imaqMorphology */
117 int frcMorphology(Image* dest, Image* source, MorphologyMethod method);
118 int frcMorphology(Image* dest, Image* source, MorphologyMethod method,
119  const StructuringElement* structuringElement);
120 /* Reject Border: calls imaqRejectBorder */
121 int frcRejectBorder(Image* dest, Image* source);
122 int frcRejectBorder(Image* dest, Image* source, int connectivity8);
123 /* Count Particles: calls imaqCountParticles */
124 int frcCountParticles(Image* image, int* numParticles);
125 /* Particle Analysis Report: calls imaqMeasureParticle */
126 int frcParticleAnalysis(Image* image, int particleNumber,
128 
129 /* Image Enhancement functions */
130 
131 /* Equalize: calls imaqEqualize */
132 int frcEqualize(Image* dest, const Image* source, float min, float max);
133 int frcEqualize(Image* dest, const Image* source, float min, float max,
134  const Image* mask);
135 
136 /* Color Equalize: calls imaqColorEqualize */
137 int frcColorEqualize(Image* dest, const Image* source);
138 int frcColorEqualize(Image* dest, const Image* source, int colorEqualization);
139 
140 /* Image Thresholding & Conversion functions */
141 
142 /* Smart Threshold: calls imaqLocalThreshold */
143 int frcSmartThreshold(Image* dest, const Image* source,
144  unsigned int windowWidth, unsigned int windowHeight,
145  LocalThresholdMethod method, double deviationWeight,
146  ObjectType type);
147 int frcSmartThreshold(Image* dest, const Image* source,
148  unsigned int windowWidth, unsigned int windowHeight,
149  LocalThresholdMethod method, double deviationWeight,
150  ObjectType type, float replaceValue);
151 
152 /* Simple Threshold: calls imaqThreshold */
153 int frcSimpleThreshold(Image* dest, const Image* source, float rangeMin,
154  float rangeMax, float newValue);
155 int frcSimpleThreshold(Image* dest, const Image* source, float rangeMin,
156  float rangeMax);
157 
158 /* Color/Hue Threshold: calls imaqColorThreshold */
159 int frcColorThreshold(Image* dest, const Image* source, ColorMode mode,
160  const Range* plane1Range, const Range* plane2Range,
161  const Range* plane3Range);
162 int frcColorThreshold(Image* dest, const Image* source, int replaceValue,
163  ColorMode mode, const Range* plane1Range,
164  const Range* plane2Range, const Range* plane3Range);
165 int frcHueThreshold(Image* dest, const Image* source, const Range* hueRange);
166 int frcHueThreshold(Image* dest, const Image* source, const Range* hueRange,
167  int minSaturation);
168 
169 /* Extract ColorHue Plane: calls imaqExtractColorPlanes */
170 int frcExtractColorPlanes(const Image* image, ColorMode mode, Image* plane1,
171  Image* plane2, Image* plane3);
172 int frcExtractHuePlane(const Image* image, Image* huePlane);
173 int frcExtractHuePlane(const Image* image, Image* huePlane, int minSaturation);
int frcRejectBorder(Image *dest, Image *source)
Eliminates particles that touch the border of the image.
Definition: VisionAPI.cpp:403
int frcHueThreshold(Image *dest, const Image *source, const Range *hueRange)
A simpler version of ColorThreshold that thresholds hue range in the HSL mode.
Definition: VisionAPI.cpp:759
int frcReadImage(Image *image, const char *fileName)
Creates image object from the information in a file.
Definition: VisionAPI.cpp:145
int frcParticleAnalysis(Image *image, int particleNumber, ParticleAnalysisReport *par)
Conduct measurements for a single particle in an images.
Definition: VisionAPI.cpp:437
HistogramReport * frcHistogram(const Image *image, int numClasses, float min, float max)
Measures the pixel intensities in a rectangle of an image.
Definition: VisionAPI.cpp:223
int frcParticleFilter(Image *dest, Image *source, const ParticleFilterCriteria2 *criteria, int criteriaCount, const ParticleFilterOptions *options, int *numParticles)
Filters particles out of an image based on their measurements.
Definition: VisionAPI.cpp:334
int frcExtractColorPlanes(const Image *image, ColorMode mode, Image *plane1, Image *plane2, Image *plane3)
Extracts the Red, Green, Blue, or Hue, Saturation or Luminance information from a color image...
Definition: VisionAPI.cpp:800
int frcColorThreshold(Image *dest, const Image *source, ColorMode mode, const Range *plane1Range, const Range *plane2Range, const Range *plane3Range)
Applies a threshold to the Red, Green, and Blue values of a RGB image or the Hue, Saturation...
Definition: VisionAPI.cpp:709
int frcSimpleThreshold(Image *dest, const Image *source, float rangeMin, float rangeMax)
Converts a grayscale image to a binary image for Particle Analysis based on a fixed threshold...
Definition: VisionAPI.cpp:658
Image * frcCreateImage(ImageType type)
Create an image object Supports IMAQ_IMAGE_U8, IMAQ_IMAGE_I16, IMAQ_IMAGE_SGL, IMAQ_IMAGE_COMPLEX, IMAQ_IMAGE_RGB, IMAQ_IMAGE_HSL, IMAQ_IMAGE_RGB_U64 The border size is defaulted to 3 so that convolutional algorithms work at the edges.
Definition: VisionAPI.cpp:37
ColorHistogramReport * frcColorHistogram(const Image *image, int numClasses, ColorMode mode)
Calculates the histogram, or pixel distribution, of a color image.
Definition: VisionAPI.cpp:284
int frcMorphology(Image *dest, Image *source, MorphologyMethod method)
Performs morphological transformations on binary images.
Definition: VisionAPI.cpp:375
int frcGetPixelValue(const Image *image, Point pixel, PixelValue *value)
Measures the pixel intensities in a rectangle of an image.
Definition: VisionAPI.cpp:310
int frcScale(Image *dest, const Image *source, int xScale, int yScale, ScalingMode scaleMode)
Scales the entire image larger or smaller.
Definition: VisionAPI.cpp:126
Tracking functions return this structure.
Definition: VisionAPI.h:54
int frcCountParticles(Image *image, int *numParticles)
Counts the number of particles in a binary image.
Definition: VisionAPI.cpp:419
int frcWriteImage(const Image *image, const char *fileName)
Write image to a file.
Definition: VisionAPI.cpp:179
int frcCopyImage(Image *dest, const Image *source)
Copy an image object.
Definition: VisionAPI.cpp:92
int frcDispose(void *object)
Dispose of one object.
Definition: VisionAPI.cpp:48
int frcColorEqualize(Image *dest, const Image *source)
Improves contrast on a color image.
Definition: VisionAPI.cpp:575
frcParticleAnalysis returns this structure
Definition: VisionAPI.h:24
int frcExtractHuePlane(const Image *image, Image *huePlane)
Extracts the Hue information from a color image.
Definition: VisionAPI.cpp:816
int frcEqualize(Image *dest, const Image *source, float min, float max)
Improves contrast on a grayscale image.
Definition: VisionAPI.cpp:552
int frcSmartThreshold(Image *dest, const Image *source, unsigned int windowWidth, unsigned int windowHeight, LocalThresholdMethod method, double deviationWeight, ObjectType type)
Automatically thresholds a grayscale image into a binary image for Particle Analysis based on a smart...
Definition: VisionAPI.cpp:624
int frcCrop(Image *dest, const Image *source, Rect rect)
Crop image without changing the scale.
Definition: VisionAPI.cpp:108