NIVision Forward Port

Ported the NIVision libraries from the old NIVision implementation to
the new autogenerated JNI bindings.

Change-Id: I7c68ca6abef1185d59a9787e9a269d720c825e2f
This commit is contained in:
Fredric Silberberg
2014-12-24 16:39:46 -05:00
parent a55f34646d
commit 3c4a1d9a1a
18 changed files with 189 additions and 2039 deletions

View File

@@ -139,19 +139,19 @@ public class AxisCamera {
public final int height;
static final ResolutionT[] allValues = new ResolutionT[4];
/**
* Image is 640 pixels wide by 480 tall
* ImageBase is 640 pixels wide by 480 tall
*/
public static final ResolutionT k640x480 = new ResolutionT(0, 640, 480);
/**
* Image is 640 pixels wide by 360 tall
* ImageBase is 640 pixels wide by 360 tall
*/
public static final ResolutionT k640x360 = new ResolutionT(1, 640, 360);
/**
* Image is 320 pixels wide by 240 tall
* ImageBase is 320 pixels wide by 240 tall
*/
public static final ResolutionT k320x240 = new ResolutionT(2, 320, 240);
/**
* Image is 160 pixels wide by 120 tall
* ImageBase is 160 pixels wide by 120 tall
*/
public static final ResolutionT k160x120 = new ResolutionT(3, 160, 120);

View File

@@ -7,11 +7,12 @@
package edu.wpi.first.wpilibj.image;
import com.sun.jna.Pointer;
import edu.wpi.first.wpilibj.util.SortedVector;
import com.ni.vision.NIVision;
/**
* An image where each pixel is treated as either on or off.
*
* @author dtjones
*/
public class BinaryImage extends MonoImage {
@@ -26,11 +27,12 @@ public class BinaryImage extends MonoImage {
/**
* Returns the number of particles.
*
* @return The number of particles
*/
public int getNumberParticles () throws NIVisionException {
public int getNumberParticles() throws NIVisionException {
if (numParticles < 0)
numParticles = NIVision.countParticles(image);
numParticles = NIVision.imaqCountParticles(image, 1);
return numParticles;
}
@@ -38,19 +40,22 @@ public class BinaryImage extends MonoImage {
private class ParticleSizeReport {
final int index;
final double size;
public ParticleSizeReport(int index) throws NIVisionException {
if ((!(index < BinaryImage.this.getNumberParticles())) || index < 0)
throw new IndexOutOfBoundsException();
this.index = index;
size = ParticleAnalysisReport.getParticleToImagePercent(BinaryImage.this, index);
}
public ParticleAnalysisReport getParticleAnalysisReport () throws NIVisionException {
public ParticleAnalysisReport getParticleAnalysisReport() throws NIVisionException {
return new ParticleAnalysisReport(BinaryImage.this, index);
}
}
/**
* Get a particle analysis report for the particle at the given index.
*
* @param index The index of the particle to report on.
* @return The ParticleAnalysisReport for the particle at the given index
*/
@@ -61,6 +66,7 @@ public class BinaryImage extends MonoImage {
/**
* Gets all the particle analysis reports ordered from largest area to smallest.
*
* @param size The number of particles to return
* @return An array of ParticleReports from largest area to smallest
*/
@@ -70,8 +76,8 @@ public class BinaryImage extends MonoImage {
ParticleSizeReport[] reports = new ParticleSizeReport[size];
SortedVector sorter = new SortedVector(new SortedVector.Comparator() {
public int compare(Object object1, Object object2) {
ParticleSizeReport p1 = (ParticleSizeReport)object1;
ParticleSizeReport p2 = (ParticleSizeReport)object2;
ParticleSizeReport p1 = (ParticleSizeReport) object1;
ParticleSizeReport p2 = (ParticleSizeReport) object2;
if (p1.size < p2.size)
return -1;
else if (p1.size > p2.size)
@@ -91,6 +97,7 @@ public class BinaryImage extends MonoImage {
/**
* Gets all the particle analysis reports ordered from largest area to smallest.
*
* @return An array of ParticleReports from largest are to smallest
*/
public ParticleAnalysisReport[] getOrderedParticleAnalysisReports() throws NIVisionException {
@@ -99,19 +106,9 @@ public class BinaryImage extends MonoImage {
public void write(String fileName) throws NIVisionException {
Pointer colorTable = new Pointer(1024);
//Black Background
colorTable.setByte(0, (byte)0); //B
colorTable.setByte(1, (byte)0); //G
colorTable.setByte(2, (byte)0); //R
colorTable.setByte(3, (byte)0); //Alpha
//Red Particles:
colorTable.setByte(4, (byte)0); //B
colorTable.setByte(5, (byte)0); //G
colorTable.setByte(6, (byte)255); //R
colorTable.setByte(7, (byte)0); //Alpha
NIVision.RGBValue colorTable = new NIVision.RGBValue(0, 0, 255, 0);
try {
NIVision.writeFile(image, fileName, colorTable);
NIVision.imaqWriteFile(image, fileName, colorTable);
} finally {
colorTable.free();
}
@@ -121,60 +118,50 @@ public class BinaryImage extends MonoImage {
* removeSmallObjects filters particles based on their size.
* The algorithm erodes the image a specified number of times and keeps the
* particles from the original image that remain in the eroded image.
*
* @param connectivity8 true to use connectivity-8 or false for connectivity-4 to determine
* whether particles are touching. For more information about connectivity, see Chapter 9,
* Binary Morphology, in the NI Vision Concepts manual.
* @param erosions the number of erosions to perform
* whether particles are touching. For more information about connectivity, see Chapter 9,
* Binary Morphology, in the NI Vision Concepts manual.
* @param erosions the number of erosions to perform
* @return a BinaryImage after applying the filter
* @throws NIVisionException
*/
public BinaryImage removeSmallObjects(boolean connectivity8, int erosions) throws NIVisionException {
BinaryImage result = new BinaryImage();
try {
NIVision.sizeFilter(result.image, image, connectivity8, erosions, true);
} catch (NIVisionException ex) {
result.free();
throw ex;
}
NIVision.imaqSizeFilter(result.image, image, connectivity8 ? 1 : 0, erosions, NIVision.SizeType.KEEP_LARGE, null);
result.free();
return result;
}
/**
* removeLargeObjects filters particles based on their size.
* The algorithm erodes the image a specified number of times and discards the
* particles from the original image that remain in the eroded image.
* @param connectivity8 true to use connectivity-8 or false for connectivity-4 to determine
* whether particles are touching. For more information about connectivity, see Chapter 9,
* Binary Morphology, in the NI Vision Concepts manual.
* @param erosions the number of erosions to perform
* @return a BinaryImage after applying the filter
* @throws NIVisionException
*/
* removeLargeObjects filters particles based on their size.
* The algorithm erodes the image a specified number of times and discards the
* particles from the original image that remain in the eroded image.
*
* @param connectivity8 true to use connectivity-8 or false for connectivity-4 to determine
* whether particles are touching. For more information about connectivity, see Chapter 9,
* Binary Morphology, in the NI Vision Concepts manual.
* @param erosions the number of erosions to perform
* @return a BinaryImage after applying the filter
* @throws NIVisionException
*/
public BinaryImage removeLargeObjects(boolean connectivity8, int erosions) throws NIVisionException {
BinaryImage result = new BinaryImage();
try {
NIVision.sizeFilter(result.image, image, connectivity8, erosions, false);
} catch (NIVisionException ex) {
result.free();
throw ex;
}
NIVision.imaqSizeFilter(result.image, image, connectivity8 ? 1 : 0, erosions, NIVision.SizeType.KEEP_SMALL, null);
return result;
}
public BinaryImage convexHull(boolean connectivity8) throws NIVisionException {
BinaryImage result = new BinaryImage();
try {
NIVision.convexHull(result.image, image, connectivity8 ? 1 : 0);
} catch (NIVisionException ex) {
result.free();
throw ex;
}
NIVision.imaqConvexHull(result.image, image, connectivity8 ? 1 : 0);
return result;
}
public BinaryImage particleFilter(CriteriaCollection criteria) throws NIVisionException {
public BinaryImage particleFilter(NIVision.ParticleFilterCriteria2[] criteria) throws NIVisionException {
BinaryImage result = new BinaryImage();
NIVision.particleFilter(result.image, image, criteria);
NIVision.ParticleFilterOptions2 options = new NIVision.ParticleFilterOptions2(0, 0, 0, 1);
NIVision.imaqParticleFilter4(result.image, image, criteria, options, null);
options.free();
return result;
}
}

View File

@@ -6,11 +6,14 @@
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.image;
import com.ni.vision.NIVision;
/**
* A class representing a color image.
*
* @author dtjones
*/
public abstract class ColorImage extends Image {
public abstract class ColorImage extends ImageBase {
ColorImage(NIVision.ImageType type) throws NIVisionException {
super(type);
@@ -28,216 +31,215 @@ public abstract class ColorImage extends Image {
NIVision.Range range1 = new NIVision.Range(low1, high1);
NIVision.Range range2 = new NIVision.Range(low2, high2);
NIVision.Range range3 = new NIVision.Range(low3, high3);
try {
NIVision.colorThreshold(res.image, image, colorMode, range1.getPointer(), range2.getPointer(), range3.getPointer());
} catch (NIVisionException e) {
res.free();
throw e;
} finally {
range1.free();
range2.free();
range3.free();
}
NIVision.imaqColorThreshold(res.image, image, 1, colorMode, range1, range2, range3);
res.free();
range1.free();
range2.free();
range3.free();
return res;
}
/**
* Return a mask of the areas of the image that fall within the given ranges for color values
* @param redLow The lower red limit.
* @param redHigh The upper red limit.
* @param greenLow The lower green limit.
*
* @param redLow The lower red limit.
* @param redHigh The upper red limit.
* @param greenLow The lower green limit.
* @param greenHigh The upper green limit.
* @param blueLow The lower blue limit.
* @param blueHigh The upper blue limit.
* @param blueLow The lower blue limit.
* @param blueHigh The upper blue limit.
* @return A BinaryImage masking the areas which match the given thresholds.
*/
public BinaryImage thresholdRGB(int redLow, int redHigh, int greenLow, int greenHigh, int blueLow, int blueHigh) throws NIVisionException {
return threshold(NIVision.ColorMode.IMAQ_RGB, redLow, redHigh, greenLow, greenHigh, blueLow, blueHigh);
return threshold(NIVision.ColorMode.RGB, redLow, redHigh, greenLow, greenHigh, blueLow, blueHigh);
}
/**
* Return a mask of the areas of the image that fall within the given ranges for color values
* @param hueLow The lower hue limit.
* @param hueHigh The upper hue limit.
* @param saturationLow The lower saturation limit.
*
* @param hueLow The lower hue limit.
* @param hueHigh The upper hue limit.
* @param saturationLow The lower saturation limit.
* @param saturationHigh The upper saturation limit.
* @param luminenceLow The lower luminence limit.
* @param luminenceHigh The upper luminence limit.
* @param luminenceLow The lower luminence limit.
* @param luminenceHigh The upper luminence limit.
* @return A BinaryImage masking the areas which match the given thresholds.
*/
public BinaryImage thresholdHSL(int hueLow, int hueHigh, int saturationLow, int saturationHigh, int luminenceLow, int luminenceHigh) throws NIVisionException {
return threshold(NIVision.ColorMode.IMAQ_HSL, hueLow, hueHigh, saturationLow, saturationHigh, luminenceLow, luminenceHigh);
return threshold(NIVision.ColorMode.HSL, hueLow, hueHigh, saturationLow, saturationHigh, luminenceLow, luminenceHigh);
}
/**
* Return a mask of the areas of the image that fall within the given ranges for color values
* @param hueLow The lower hue limit.
* @param hueHigh The upper hue limit.
* @param saturationLow The lower saturation limit.
*
* @param hueLow The lower hue limit.
* @param hueHigh The upper hue limit.
* @param saturationLow The lower saturation limit.
* @param saturationHigh The upper saturation limit.
* @param valueHigh The lower value limit.
* @param valueLow The upper value limit.
* @param valueHigh The lower value limit.
* @param valueLow The upper value limit.
* @return A BinaryImage masking the areas which match the given thresholds.
*/
public BinaryImage thresholdHSV(int hueLow, int hueHigh, int saturationLow, int saturationHigh, int valueLow, int valueHigh) throws NIVisionException {
return threshold(NIVision.ColorMode.IMAQ_HSV, hueLow, hueHigh, saturationLow, saturationHigh, valueLow, valueHigh);
return threshold(NIVision.ColorMode.HSV, hueLow, hueHigh, saturationLow, saturationHigh, valueLow, valueHigh);
}
/**
* Return a mask of the areas of the image that fall within the given ranges for color values
* @param hueLow The lower hue limit.
* @param hueHigh The upper hue limit.
* @param saturationLow The lower saturation limit.
*
* @param hueLow The lower hue limit.
* @param hueHigh The upper hue limit.
* @param saturationLow The lower saturation limit.
* @param saturationHigh The upper saturation limit.
* @param intansityLow The lower intensity limit.
* @param intensityHigh The upper intensity limit.
* @param intansityLow The lower intensity limit.
* @param intensityHigh The upper intensity limit.
* @return A BinaryImage masking the areas which match the given thresholds.
*/
public BinaryImage thresholdHSI(int hueLow, int hueHigh, int saturationLow, int saturationHigh, int intansityLow, int intensityHigh) throws NIVisionException {
return threshold(NIVision.ColorMode.IMAQ_HSI, hueLow, hueHigh, saturationLow, saturationHigh, intansityLow, intensityHigh);
return threshold(NIVision.ColorMode.HSI, hueLow, hueHigh, saturationLow, saturationHigh, intansityLow, intensityHigh);
}
MonoImage extractFirstColorPlane(NIVision.ColorMode mode) throws NIVisionException {
MonoImage result = new MonoImage();
try {
NIVision.extractColorPlanes(image, mode, result.image, null, null);
} catch (NIVisionException e) {
result.free();
throw e;
}
NIVision.imaqExtractColorPlanes(image, mode, result.image, null, null);
result.free();
return result;
}
MonoImage extractSecondColorPlane(NIVision.ColorMode mode) throws NIVisionException {
MonoImage result = new MonoImage();
try {
NIVision.extractColorPlanes(image, mode, null, result.image, null);
} catch (NIVisionException e) {
result.free();
throw e;
}
NIVision.imaqExtractColorPlanes(image, mode, null, result.image, null);
result.free();
return result;
}
MonoImage extractThirdColorPlane(NIVision.ColorMode mode) throws NIVisionException {
MonoImage result = new MonoImage();
try {
NIVision.extractColorPlanes(image, mode, null, null, result.image);
} catch (NIVisionException e) {
result.free();
throw e;
}
NIVision.imaqExtractColorPlanes(image, mode, null, null, result.image);
result.free();
return result;
}
/**
* Get the red color plane from the image when represented in RGB color space.
*
* @return The red color plane from the image.
*/
public MonoImage getRedPlane() throws NIVisionException {
return extractFirstColorPlane(NIVision.ColorMode.IMAQ_RGB);
return extractFirstColorPlane(NIVision.ColorMode.RGB);
}
/**
* Get the green color plane from the image when represented in RGB color space.
*
* @return The green color plane from the image.
*/
public MonoImage getGreenPlane() throws NIVisionException {
return extractSecondColorPlane(NIVision.ColorMode.IMAQ_RGB);
return extractSecondColorPlane(NIVision.ColorMode.RGB);
}
/**
* Get the blue color plane from the image when represented in RGB color space.
*
* @return The blue color plane from the image.
*/
public MonoImage getBluePlane() throws NIVisionException {
return extractThirdColorPlane(NIVision.ColorMode.IMAQ_RGB);
return extractThirdColorPlane(NIVision.ColorMode.RGB);
}
/**
* Get the hue color plane from the image when represented in HSL color space.
*
* @return The hue color plane from the image.
*/
public MonoImage getHSLHuePlane() throws NIVisionException {
return extractFirstColorPlane(NIVision.ColorMode.IMAQ_HSL);
return extractFirstColorPlane(NIVision.ColorMode.HSL);
}
/**
* Get the hue color plane from the image when represented in HSV color space.
*
* @return The hue color plane from the image.
*/
public MonoImage getHSVHuePlane() throws NIVisionException {
return extractFirstColorPlane(NIVision.ColorMode.IMAQ_HSV);
return extractFirstColorPlane(NIVision.ColorMode.HSV);
}
/**
* Get the hue color plane from the image when represented in HSI color space.
*
* @return The hue color plane from the image.
*/
public MonoImage getHSIHuePlane() throws NIVisionException {
return extractFirstColorPlane(NIVision.ColorMode.IMAQ_HSI);
return extractFirstColorPlane(NIVision.ColorMode.HSI);
}
/**
* Get the saturation color plane from the image when represented in HSL color space.
*
* @return The saturation color plane from the image.
*/
public MonoImage getHSLSaturationPlane() throws NIVisionException {
return extractSecondColorPlane(NIVision.ColorMode.IMAQ_HSL);
return extractSecondColorPlane(NIVision.ColorMode.HSL);
}
/**
* Get the saturation color plane from the image when represented in HSV color space.
*
* @return The saturation color plane from the image.
*/
public MonoImage getHSVSaturationPlane() throws NIVisionException {
return extractSecondColorPlane(NIVision.ColorMode.IMAQ_HSV);
return extractSecondColorPlane(NIVision.ColorMode.HSV);
}
/**
* Get the saturation color plane from the image when represented in HSI color space.
*
* @return The saturation color plane from the image.
*/
public MonoImage getHSISaturationPlane() throws NIVisionException {
return extractSecondColorPlane(NIVision.ColorMode.IMAQ_HSI);
return extractSecondColorPlane(NIVision.ColorMode.HSI);
}
/**
* Get the luminance color plane from the image when represented in HSL color space.
*
* @return The luminance color plane from the image.
*/
public MonoImage getLuminancePlane() throws NIVisionException {
return extractThirdColorPlane(NIVision.ColorMode.IMAQ_HSL);
return extractThirdColorPlane(NIVision.ColorMode.HSL);
}
/**
* Get the value color plane from the image when represented in HSV color space.
*
* @return The value color plane from the image.
*/
public MonoImage getValuePlane() throws NIVisionException {
return extractThirdColorPlane(NIVision.ColorMode.IMAQ_HSV);
return extractThirdColorPlane(NIVision.ColorMode.HSV);
}
/**
* Get the intensity color plane from the image when represented in HSI color space.
*
* @return The intensity color plane from the image.
*/
public MonoImage getIntensityPlane() throws NIVisionException {
return extractThirdColorPlane(NIVision.ColorMode.IMAQ_HSI);
return extractThirdColorPlane(NIVision.ColorMode.HSI);
}
ColorImage replaceFirstColorPlane(NIVision.ColorMode mode, MonoImage plane) throws NIVisionException {
NIVision.replaceColorPlanes(image, image, mode, plane.image, null, null);
NIVision.imaqReplaceColorPlanes(image, image, mode, plane.image, null, null);
return this;
}
ColorImage replaceSecondColorPlane(NIVision.ColorMode mode, MonoImage plane) throws NIVisionException {
NIVision.replaceColorPlanes(image, image, mode, null, plane.image, null);
NIVision.imaqReplaceColorPlanes(image, image, mode, null, plane.image, null);
return this;
}
ColorImage replaceThirdColorPlane(NIVision.ColorMode mode, MonoImage plane) throws NIVisionException {
NIVision.replaceColorPlanes(image, image, mode, null, null, plane.image);
NIVision.imaqReplaceColorPlanes(image, image, mode, null, null, plane.image);
return this;
}
@@ -245,132 +247,144 @@ public abstract class ColorImage extends Image {
* Set the red color plane from the image when represented in RGB color space.
* This does not create a new image, but modifies this one instead. Create a
* copy before hand if you need to continue using the original.
*
* @param plane The MonoImage representing the new color plane.
* @return The resulting image.
*/
public ColorImage replaceRedPlane(MonoImage plane) throws NIVisionException {
return replaceFirstColorPlane(NIVision.ColorMode.IMAQ_RGB, plane);
return replaceFirstColorPlane(NIVision.ColorMode.RGB, plane);
}
/**
* Set the green color plane from the image when represented in RGB color space.
* This does not create a new image, but modifies this one instead. Create a
* copy before hand if you need to continue using the original.
*
* @param plane The MonoImage representing the new color plane.
* @return The resulting image.
*/
public ColorImage replaceGreenPlane(MonoImage plane) throws NIVisionException {
return replaceSecondColorPlane(NIVision.ColorMode.IMAQ_RGB, plane);
return replaceSecondColorPlane(NIVision.ColorMode.RGB, plane);
}
/**
* Set the blue color plane from the image when represented in RGB color space.
* This does not create a new image, but modifies this one instead. Create a
* copy before hand if you need to continue using the original.
*
* @param plane The MonoImage representing the new color plane.
* @return The resulting image.
*/
public ColorImage replaceBluePlane(MonoImage plane) throws NIVisionException {
return replaceThirdColorPlane(NIVision.ColorMode.IMAQ_RGB, plane);
return replaceThirdColorPlane(NIVision.ColorMode.RGB, plane);
}
/**
* Set the hue color plane from the image when represented in HSL color space.
* This does not create a new image, but modifies this one instead. Create a
* copy before hand if you need to continue using the original.
*
* @param plane The MonoImage representing the new color plane.
* @return The resulting image.
*/
public ColorImage replaceHSLHuePlane(MonoImage plane) throws NIVisionException {
return replaceFirstColorPlane(NIVision.ColorMode.IMAQ_HSL, plane);
return replaceFirstColorPlane(NIVision.ColorMode.HSL, plane);
}
/**
* Set the hue color plane from the image when represented in HSV color space.
* This does not create a new image, but modifies this one instead. Create a
* copy before hand if you need to continue using the original.
*
* @param plane The MonoImage representing the new color plane.
* @return The resulting image.
*/
public ColorImage replaceHSVHuePlane(MonoImage plane) throws NIVisionException {
return replaceFirstColorPlane(NIVision.ColorMode.IMAQ_HSV, plane);
return replaceFirstColorPlane(NIVision.ColorMode.HSV, plane);
}
/**
* Set the hue color plane from the image when represented in HSI color space.
* This does not create a new image, but modifies this one instead. Create a
* copy before hand if you need to continue using the original.
*
* @param plane The MonoImage representing the new color plane.
* @return The resulting image.
*/
public ColorImage replaceHSIHuePlane(MonoImage plane) throws NIVisionException {
return replaceFirstColorPlane(NIVision.ColorMode.IMAQ_HSI, plane);
return replaceFirstColorPlane(NIVision.ColorMode.HSI, plane);
}
/**
* Set the saturation color plane from the image when represented in HSL color space.
* This does not create a new image, but modifies this one instead. Create a
* copy before hand if you need to continue using the original.
*
* @param plane The MonoImage representing the new color plane.
* @return The resulting image.
*/
public ColorImage replaceHSLSaturationPlane(MonoImage plane) throws NIVisionException {
return replaceSecondColorPlane(NIVision.ColorMode.IMAQ_HSL, plane);
return replaceSecondColorPlane(NIVision.ColorMode.HSL, plane);
}
/**
* Set the saturation color plane from the image when represented in HSV color space.
* This does not create a new image, but modifies this one instead. Create a
* copy before hand if you need to continue using the original.
*
* @param plane The MonoImage representing the new color plane.
* @return The resulting image.
*/
public ColorImage replaceHSVSaturationPlane(MonoImage plane) throws NIVisionException {
return replaceSecondColorPlane(NIVision.ColorMode.IMAQ_HSV, plane);
return replaceSecondColorPlane(NIVision.ColorMode.HSV, plane);
}
/**
* Set the saturation color plane from the image when represented in HSI color space.
* This does not create a new image, but modifies this one instead. Create a
* copy before hand if you need to continue using the original.
*
* @param plane The MonoImage representing the new color plane.
* @return The resulting image.
*/
public ColorImage replaceHSISaturationPlane(MonoImage plane) throws NIVisionException {
return replaceSecondColorPlane(NIVision.ColorMode.IMAQ_HSI, plane);
return replaceSecondColorPlane(NIVision.ColorMode.HSI, plane);
}
/**
* Set the luminance color plane from the image when represented in HSL color space.
* This does not create a new image, but modifies this one instead. Create a
* copy before hand if you need to continue using the original.
*
* @param plane The MonoImage representing the new color plane.
* @return The resulting image.
*/
public ColorImage replaceLuminancePlane(MonoImage plane) throws NIVisionException {
return replaceThirdColorPlane(NIVision.ColorMode.IMAQ_HSL, plane);
return replaceThirdColorPlane(NIVision.ColorMode.HSL, plane);
}
/**
* Set the value color plane from the image when represented in HSV color space.
* This does not create a new image, but modifies this one instead. Create a
* copy before hand if you need to continue using the original.
*
* @param plane The MonoImage representing the new color plane.
* @return The resulting image.
*/
public ColorImage replaceValuePlane(MonoImage plane) throws NIVisionException {
return replaceThirdColorPlane(NIVision.ColorMode.IMAQ_HSV, plane);
return replaceThirdColorPlane(NIVision.ColorMode.HSV, plane);
}
/**
* Set the intensity color plane from the image when represented in HSI color space.
* This does not create a new image, but modifies this one instead. Create a
* copy before hand if you need to continue using the original.
*
* @param plane The MonoImage representing the new color plane.
* @return The resulting image.
*/
public ColorImage replaceIntensityPlane(MonoImage plane) throws NIVisionException {
return replaceThirdColorPlane(NIVision.ColorMode.IMAQ_HSI, plane);
return replaceThirdColorPlane(NIVision.ColorMode.HSI, plane);
}
/**
@@ -379,10 +393,11 @@ public abstract class ColorImage extends Image {
* groupings.
* This does not create a new image, but modifies this one instead. Create a
* copy before hand if you need to continue using the original.
*
* @return The modified image.
*/
public ColorImage colorEqualize() throws NIVisionException {
NIVision.colorEqualize(image, image, true);
NIVision.imaqColorEqualize(image, image, 1);
return this;
}
@@ -392,10 +407,11 @@ public abstract class ColorImage extends Image {
* groupings for the Luminance plane only.
* This does not create a new image, but modifies this one instead. Create a
* copy before hand if you need to continue using the original.
*
* @return The modified image.
*/
public ColorImage luminanceEqualize() throws NIVisionException {
NIVision.colorEqualize(image, image, false);
NIVision.imaqColorEqualize(image, image, 0);
return this;
}
}

View File

@@ -1,49 +0,0 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.wpilibj.image;
import com.sun.jna.Pointer;
import edu.wpi.first.wpilibj.image.NIVision.MeasurementType;
import java.util.Vector;
class ParticleFilterCriteria {
MeasurementType type;
float lower;
float upper;
boolean outsideRange;
ParticleFilterCriteria(MeasurementType type, float lower, float upper, boolean outsideRange) {
this.type = type;
this.lower = lower;
this.upper = upper;
this.outsideRange = outsideRange;
}
}
public class CriteriaCollection {
Vector criteria = new Vector();
public void addCriteria(MeasurementType type, float lower, float upper, boolean outsideRange) {
criteria.addElement(new ParticleFilterCriteria(type, lower, upper, outsideRange));
}
public int getNumberOfCriteria() {
return criteria.size();
}
public Pointer getCriteriaArray() {
Pointer p = new Pointer(criteria.size() * 5 * 4); // 5 elements each 4 bytes
for (int i = 0; i < criteria.size(); i++) {
ParticleFilterCriteria pfc = (ParticleFilterCriteria) criteria.elementAt(i);
p.setInt(i * 20, pfc.type.value);
p.setFloat(i * 20 + 4, pfc.lower);
p.setFloat(i * 20 + 8, pfc.upper);
p.setInt(i * 20 + 12, 0); // always use pixel measurements for now
p.setInt(i * 20 + 16, pfc.outsideRange ? 1 : 0);
}
return p;
}
}

View File

@@ -1,68 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.image;
import com.sun.jna.Structure;
/**
*
* @author dtjones
*/
public class CurveOptions extends Structure {
int m_extractionMode;
int m_threshold;
int m_filterSize;
int m_minLength;
int m_rowStepSize;
int m_columnStepSize;
int m_maxEndPointGap;
int m_onlyClosed;
int m_subPixelAccuracy;
public CurveOptions(int m_extractionMode, int m_threshold, int m_filterSize, int m_minLength, int m_rowStepSize, int m_columnStepSize, int m_maxEndPointGap, int m_onlyClosed, int m_subPixelAccuracy) {
this.m_extractionMode = m_extractionMode;
this.m_threshold = m_threshold;
this.m_filterSize = m_filterSize;
this.m_minLength = m_minLength;
this.m_rowStepSize = m_rowStepSize;
this.m_columnStepSize = m_columnStepSize;
this.m_maxEndPointGap = m_maxEndPointGap;
this.m_onlyClosed = m_onlyClosed;
this.m_subPixelAccuracy = m_subPixelAccuracy;
allocateMemory();
write();
}
public void read() {
}
public void write() {
backingNativeMemory.setInt(0, m_extractionMode);
backingNativeMemory.setInt(4, m_threshold);
backingNativeMemory.setInt(8, m_filterSize);
backingNativeMemory.setInt(12, m_minLength);
backingNativeMemory.setInt(16, m_rowStepSize);
backingNativeMemory.setInt(20, m_columnStepSize);
backingNativeMemory.setInt(24, m_maxEndPointGap);
backingNativeMemory.setInt(28, m_onlyClosed);
backingNativeMemory.setInt(32, m_subPixelAccuracy);
}
public int size() {
return 36;
}
public void free() {
release();
}
}

View File

@@ -1,57 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.image;
import com.sun.jna.Structure;
/**
*
* @author dtjones
*/
public class EllipseDescriptor extends Structure {
double m_minMajorRadius;
double m_maxMajorRadius;
double m_minMinorRadius;
double m_maxMinorRadius;
public EllipseDescriptor(double m_minMajorRadius, double m_maxMajorRadius, double m_minMinorRadius, double m_maxMinorRadius) {
this.m_minMajorRadius = m_minMajorRadius;
this.m_maxMajorRadius = m_maxMajorRadius;
this.m_minMinorRadius = m_minMinorRadius;
this.m_maxMinorRadius = m_maxMinorRadius;
allocateMemory();
write();
}
/**
* Free the c memory associated with this object.
*/
public void free() {
release();
}
public void read() {
m_minMajorRadius = backingNativeMemory.getDouble(0);
m_maxMajorRadius = backingNativeMemory.getDouble(8);
m_minMinorRadius = backingNativeMemory.getDouble(16);
m_maxMinorRadius = backingNativeMemory.getDouble(24);
}
public void write() {
backingNativeMemory.setDouble(0, m_minMajorRadius);
backingNativeMemory.setDouble(8, m_maxMajorRadius);
backingNativeMemory.setDouble(16, m_minMinorRadius);
backingNativeMemory.setDouble(24, m_maxMinorRadius);
}
public int size() {
return 32;
}
}

View File

@@ -1,74 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.image;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
/**
*
* @author dtjones
*/
public class EllipseMatch {
static final int ellipseMatchSize = 40;
public double m_xPos;
public double m_yPos;
public double m_rotation;
public double m_majorRadius;
public double m_minorRadius;
public double m_score;
private class EllipseMatchStructure extends Structure {
public EllipseMatchStructure(int address) {
useMemory(new Pointer(address, ellipseMatchSize));
read();
}
public void read() {
m_xPos = backingNativeMemory.getFloat(0);
m_yPos = backingNativeMemory.getFloat(4);
m_rotation = backingNativeMemory.getDouble(8);
m_majorRadius = backingNativeMemory.getDouble(16);
m_minorRadius = backingNativeMemory.getDouble(24);
m_score = backingNativeMemory.getDouble(32);
}
public void write() {
}
public int size() {
return ellipseMatchSize;
}
}
EllipseMatch(int address) {
new EllipseMatchStructure(address);
}
public String toString() {
return "Ellipse Match:\n" +
" Pos x: " + m_xPos + " y: " + m_yPos + "\n" +
" Radius major: " + m_majorRadius + " minor: " + m_minorRadius + "\n" +
" Rotation: " + m_rotation + " Score: " + m_score + "\n";
}
protected static EllipseMatch[] getMatchesFromMemory(int address, int number) {
if (address == 0) {
return new EllipseMatch[0];
}
EllipseMatch[] toReturn = new EllipseMatch[number];
for (int i = 0; i < number; i++) {
toReturn[i] = new EllipseMatch(address + i * ellipseMatchSize);
}
return toReturn;
}
}

View File

@@ -6,6 +6,8 @@
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.image;
import com.ni.vision.NIVision;
/**
* A color image represented in HSL color space at 3 bytes per pixel.
* @author dtjones
@@ -16,7 +18,7 @@ public class HSLImage extends ColorImage {
* Create a new 0x0 image.
*/
public HSLImage() throws NIVisionException {
super(NIVision.ImageType.imaqImageHSL);
super(NIVision.ImageType.IMAGE_HSL);
}
HSLImage(HSLImage sourceImage) {
@@ -28,7 +30,7 @@ public class HSLImage extends ColorImage {
* @param fileName The path of the file to load.
*/
public HSLImage(String fileName) throws NIVisionException {
super(NIVision.ImageType.imaqImageHSL);
NIVision.readFile(image, fileName);
super(NIVision.ImageType.IMAGE_HSL);
NIVision.imaqReadFile(image, fileName);
}
}

View File

@@ -6,21 +6,22 @@
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.image;
import com.sun.jna.Pointer;
import com.ni.vision.NIVision;
import com.ni.vision.NIVision.Image;
/**
* Class representing a generic image.
* @author dtjones
*/
public abstract class Image {
public abstract class ImageBase {
/**
* Pointer to the image memory
*/
public final Pointer image;
public final Image image;
static final int DEFAULT_BORDER_SIZE = 3;
Image(NIVision.ImageType type) throws NIVisionException {
ImageBase(NIVision.ImageType type) throws NIVisionException {
image = NIVision.imaqCreateImage(type, DEFAULT_BORDER_SIZE);
}
@@ -30,7 +31,7 @@ public abstract class Image {
* one will free both.
* @param sourceImage The image to reference
*/
Image(Image sourceImage) {
ImageBase(ImageBase sourceImage) {
image = sourceImage.image;
}
@@ -48,14 +49,16 @@ public abstract class Image {
* @param fileName The path to write the image to.
*/
public void write(String fileName) throws NIVisionException {
NIVision.writeFile(image, fileName);
NIVision.RGBValue value = new NIVision.RGBValue();
NIVision.imaqWriteFile(image, fileName, value);
value.free();
}
/**
* Release the memory associated with an image.
*/
public void free() throws NIVisionException {
NIVision.dispose(image);
image.free();
}
/**
@@ -63,7 +66,7 @@ public abstract class Image {
* @return The height of the image.
*/
public int getHeight() throws NIVisionException {
return NIVision.getHeight(image);
return NIVision.imaqGetImageSize(image).height;
}
/**
@@ -71,6 +74,6 @@ public abstract class Image {
* @return The width of the image.
*/
public int getWidth() throws NIVisionException {
return NIVision.getWidth(image);
return NIVision.imaqGetImageSize(image).width;
}
}

View File

@@ -1,121 +0,0 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.wpilibj.image;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
/**
*
* @author koconnor
*/
public class LinearAverages {
Pointer columnAveragesPtr;
int columnCount;
float[] columnAverages;
Pointer rowAveragesPtr;
int rowCount;
float[] rowAverages;
Pointer risingDiagAveragesPtr;
int risingDiagCount;
float[] risingDiagAverages;
Pointer fallingDiagAveragesPtr;
int fallingDiagCount;
float[] fallingDiagAverages;
public static class LinearAveragesMode {
public final int value;
static final int IMAQ_COLUMN_AVERAGES_val = 1;
static final int IMAQ_ROW_AVERAGES_val = 2;
static final int IMAQ_RISING_DIAG_AVERAGES_val = 4;
static final int IMAQ_FALLING_DIAG_AVERAGES_val = 8;
static final int IMAQ_ALL_LINEAR_AVERAGES_val = 15;
public static final LinearAveragesMode IMAQ_COLUMN_AVERAGES = new LinearAveragesMode(IMAQ_COLUMN_AVERAGES_val);
public static final LinearAveragesMode IMAQ_ROW_AVERAGES = new LinearAveragesMode(IMAQ_ROW_AVERAGES_val);
public static final LinearAveragesMode IMAQ_RISING_DIAG_AVERAGES = new LinearAveragesMode(IMAQ_RISING_DIAG_AVERAGES_val);
public static final LinearAveragesMode IMAQ_FALLING_DIAG_AVERAGES = new LinearAveragesMode(IMAQ_FALLING_DIAG_AVERAGES_val);
public static final LinearAveragesMode IMAQ_ALL_LINEAR_AVERAGES = new LinearAveragesMode(IMAQ_ALL_LINEAR_AVERAGES_val);
private LinearAveragesMode (int value) {
this.value = value;
}
}
private class LinearAveragesStruct extends Structure {
public void read() {
columnCount = backingNativeMemory.getInt(4);
columnAveragesPtr = backingNativeMemory.getPointer(0, 4*columnCount);
columnAverages = new float[columnCount];
columnAveragesPtr.getFloats(0, columnAverages, 0, columnCount);
rowCount = backingNativeMemory.getInt(12);
rowAveragesPtr = backingNativeMemory.getPointer(8, 4*rowCount);
rowAverages = new float[rowCount];
rowAveragesPtr.getFloats(0, rowAverages, 0, rowCount);
risingDiagCount = backingNativeMemory.getInt(20);
risingDiagAveragesPtr = backingNativeMemory.getPointer(16, 4*risingDiagCount);
risingDiagAverages = new float[risingDiagCount];
risingDiagAveragesPtr.getFloats(0, risingDiagAverages, 0, risingDiagCount);
fallingDiagCount = backingNativeMemory.getInt(28);
fallingDiagAveragesPtr = backingNativeMemory.getPointer(24, 4*fallingDiagCount);
fallingDiagAverages = new float[fallingDiagCount];
fallingDiagAveragesPtr.getFloats(0, fallingDiagAverages, 0, fallingDiagCount);
}
public void write() {
backingNativeMemory.setPointer(0, columnAveragesPtr);
backingNativeMemory.setInt(4, columnCount);
backingNativeMemory.setPointer(8, rowAveragesPtr);
backingNativeMemory.setInt(12, rowCount);
backingNativeMemory.setPointer(16, risingDiagAveragesPtr);
backingNativeMemory.setInt(20, risingDiagCount);
backingNativeMemory.setPointer(24, fallingDiagAveragesPtr);
backingNativeMemory.setInt(28, fallingDiagCount);
}
public int size() {
return 32;
}
/**
* Free the memory used by this range
*/
public void free() {
release();
}
/**
* Create a new range with the specified upper and lower boundaries
* @param lower The lower limit
* @param upper The upper limit
*/
public LinearAveragesStruct(int address) {
useMemory(new Pointer(address, size()));
read();
}
}
LinearAverages(int address) {
new LinearAveragesStruct(address);
}
public float[] getColumnAverages() {
return columnAverages;
}
public float[] getRowAverages() {
return rowAverages;
}
public float[] getRisingDiagAverages() {
return risingDiagAverages;
}
public float[] getFallingDiagAverages() {
return fallingDiagAverages;
}
}

View File

@@ -6,31 +6,38 @@
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.image;
import com.ni.vision.NIVision;
import com.ni.vision.NIVision.EllipseDescriptor;
import com.ni.vision.NIVision.CurveOptions;
import com.ni.vision.NIVision.ShapeDetectionOptions;
import com.ni.vision.NIVision.ROI;
import com.ni.vision.NIVision.DetectEllipsesResult;
/**
* A grey scale image represented at a byte per pixel.
* @author dtjones
*/
public class MonoImage extends Image {
public class MonoImage extends ImageBase {
/**
* Create a new 0x0 image.
*/
public MonoImage() throws NIVisionException {
super(NIVision.ImageType.imaqImageU8);
super(NIVision.ImageType.IMAGE_U8);
}
MonoImage(MonoImage sourceImage) {
super(sourceImage);
}
public EllipseMatch[] detectEllipses(EllipseDescriptor ellipseDescriptor,
public DetectEllipsesResult detectEllipses(EllipseDescriptor ellipseDescriptor,
CurveOptions curveOptions, ShapeDetectionOptions shapeDetectionOptions,
RegionOfInterest roi) throws NIVisionException {
return NIVision.detectEllipses(this, ellipseDescriptor, curveOptions, shapeDetectionOptions, roi);
ROI roi) throws NIVisionException {
return NIVision.imaqDetectEllipses(image, ellipseDescriptor, curveOptions, shapeDetectionOptions, roi);
}
public EllipseMatch[] detectEllipses(EllipseDescriptor ellipseDescriptor)
public DetectEllipsesResult detectEllipses(EllipseDescriptor ellipseDescriptor)
throws NIVisionException {
return NIVision.detectEllipses(this, ellipseDescriptor, null, null, null);
return NIVision.imaqDetectEllipses(image, ellipseDescriptor, null, null, null);
}
}

View File

@@ -422,7 +422,7 @@ public class NIVisionException extends Exception {
case -1074395879:
return "Invalid measure number.";
case -1074395878:
return "The Image Display control does not support writing this property node.";
return "The ImageBase Display control does not support writing this property node.";
case -1074395877:
return "The specified color mode requires the use of imaqChangeColorSpace2.";
case -1074395876:

View File

@@ -6,6 +6,8 @@
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.image;
import com.ni.vision.NIVision;
/**
* Class to store commonly used information about a particle.
* @author dtjones
@@ -52,21 +54,21 @@ public class ParticleAnalysisReport {
ParticleAnalysisReport(BinaryImage image, int index) throws NIVisionException {
imageHeight = image.getHeight();
imageWidth = image.getWidth();
center_mass_x = (int) NIVision.MeasureParticle(image.image, index, false, NIVision.MeasurementType.IMAQ_MT_CENTER_OF_MASS_X);
center_mass_y = (int) NIVision.MeasureParticle(image.image, index, false, NIVision.MeasurementType.IMAQ_MT_CENTER_OF_MASS_Y);
center_mass_x = (int) NIVision.imaqMeasureParticle(image.image, index, 0, NIVision.MeasurementType.MT_CENTER_OF_MASS_X);
center_mass_y = (int) NIVision.imaqMeasureParticle(image.image, index, 0, NIVision.MeasurementType.MT_CENTER_OF_MASS_Y);
center_mass_x_normalized = (2.0 * center_mass_x / imageWidth) - 1.0;
center_mass_y_normalized = (2.0 * center_mass_y / imageHeight) - 1.0;
particleArea = NIVision.MeasureParticle(image.image, index, false, NIVision.MeasurementType.IMAQ_MT_AREA);
boundingRectLeft = (int) NIVision.MeasureParticle(image.image, index, false, NIVision.MeasurementType.IMAQ_MT_BOUNDING_RECT_LEFT);
boundingRectTop = (int) NIVision.MeasureParticle(image.image, index, false, NIVision.MeasurementType.IMAQ_MT_BOUNDING_RECT_TOP);
boundingRectWidth = (int) NIVision.MeasureParticle(image.image, index, false, NIVision.MeasurementType.IMAQ_MT_BOUNDING_RECT_WIDTH);
boundingRectHeight = (int) NIVision.MeasureParticle(image.image, index, false, NIVision.MeasurementType.IMAQ_MT_BOUNDING_RECT_HEIGHT);
particleToImagePercent = NIVision.MeasureParticle(image.image, index, false, NIVision.MeasurementType.IMAQ_MT_AREA_BY_IMAGE_AREA);
particleQuality = NIVision.MeasureParticle(image.image, index, false, NIVision.MeasurementType.IMAQ_MT_AREA_BY_PARTICLE_AND_HOLES_AREA);
particleArea = NIVision.imaqMeasureParticle(image.image, index, 0, NIVision.MeasurementType.MT_AREA);
boundingRectLeft = (int) NIVision.imaqMeasureParticle(image.image, index, 0, NIVision.MeasurementType.MT_BOUNDING_RECT_LEFT);
boundingRectTop = (int) NIVision.imaqMeasureParticle(image.image, index, 0, NIVision.MeasurementType.MT_BOUNDING_RECT_TOP);
boundingRectWidth = (int) NIVision.imaqMeasureParticle(image.image, index, 0, NIVision.MeasurementType.MT_BOUNDING_RECT_WIDTH);
boundingRectHeight = (int) NIVision.imaqMeasureParticle(image.image, index, 0, NIVision.MeasurementType.MT_BOUNDING_RECT_HEIGHT);
particleToImagePercent = NIVision.imaqMeasureParticle(image.image, index, 0, NIVision.MeasurementType.MT_AREA_BY_IMAGE_AREA);
particleQuality = NIVision.imaqMeasureParticle(image.image, index, 0, NIVision.MeasurementType.MT_AREA_BY_PARTICLE_AND_HOLES_AREA);
}
static double getParticleToImagePercent(BinaryImage image, int index) throws NIVisionException {
return NIVision.MeasureParticle(image.image, index, false, NIVision.MeasurementType.IMAQ_MT_AREA_BY_IMAGE_AREA);
return NIVision.imaqMeasureParticle(image.image, index, 0, NIVision.MeasurementType.MT_AREA_BY_IMAGE_AREA);
}
/**

View File

@@ -7,6 +7,8 @@
package edu.wpi.first.wpilibj.image;
import com.ni.vision.NIVision;
/**
* A color image represented in RGB color space at 3 bytes per pixel.
* @author dtjones
@@ -17,7 +19,7 @@ public class RGBImage extends ColorImage {
* Create a new 0x0 image.
*/
public RGBImage() throws NIVisionException {
super(NIVision.ImageType.imaqImageRGB);
super(NIVision.ImageType.IMAGE_RGB);
}
RGBImage(RGBImage sourceImage) {
@@ -29,7 +31,7 @@ public class RGBImage extends ColorImage {
* @param fileName The path of the file to load.
*/
public RGBImage(String fileName) throws NIVisionException {
super(NIVision.ImageType.imaqImageRGB);
NIVision.readFile(image, fileName);
super(NIVision.ImageType.IMAGE_RGB);
NIVision.imaqReadFile(image, fileName);
}
}

View File

@@ -1,28 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.image;
import com.sun.jna.Structure;
/**
* This is a dummy class which needs to be filled in.
* @author dtjones
*/
public class RegionOfInterest extends Structure {
public void read() {
}
public void write() {
}
public int size() {
return 0;
}
}

View File

@@ -1,71 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.image;
import com.sun.jna.Structure;
/**
*
* @author dtjones
*/
public class ShapeDetectionOptions extends Structure {
int mode; //unsigned int Specifies the method used when looking for the shape in the image. Combine values from the GeometricMatchingMode enumeration to specify the value of this element.
int angleRanges; //RangeFloat* An array of angle ranges, in degrees, where each range specifies how much you expect the shape to be rotated in the image. To decrease the search time, limit the degrees of rotation in which you expect to find the shape in the image. Set this element to NULL to allow all angles. This function ignores this range if mode does not include IMAQ_GEOMETRIC_MATCH_ROTATION_INVARIANT.
int numAngleRanges; //int The size of the orientationRanges array.
float scaleRangeMin; // RangeFloat A range that specifies the sizes of the shapes you expect to be in the image, expressed as a ratio percentage representing the size of the pattern in the image divided by size of the original pattern multiplied by 100. This function ignores this range if mode does not include IMAQ_GEOMETRIC_MATCH_SCALE_INVARIANT
float scaleRangeMax;
double minMatchScore; // double The minimum score a match can have for the function to consider the match valid. Acceptable values range from 0 to 1,000.
public static final int IMAQ_GEOMETRIC_MATCH_SHIFT_INVARIANT = 0; // Searches for occurrences of the pattern in the image, assuming that the pattern is not rotated more than plus or minus 5 degrees.
public static final int IMAQ_GEOMETRIC_MATCH_ROTATION_INVARIANT = 1; // Searches for occurrences of the pattern in the image with reduced restriction on the rotation of the pattern.
public static final int IMAQ_GEOMETRIC_MATCH_SCALE_INVARIANT = 2; // Searches for occurrences of the pattern in the image with reduced restriction on the size of the pattern.
public static final int IMAQ_GEOMETRIC_MATCH_OCCLUSION_INVARIANT = 4; // Searches for occurrences of the pattern in the image, allowing for a specified percentage of the pattern to be occluded.
public ShapeDetectionOptions(int mode, int angleRanges, int numAngleRanges, float scaleRangeMin, float scaleRangeMax, double minMatchScore) {
this.mode = mode;
this.angleRanges = angleRanges;
this.numAngleRanges = numAngleRanges;
this.scaleRangeMin = scaleRangeMin;
this.scaleRangeMax = scaleRangeMax;
this.minMatchScore = minMatchScore;
allocateMemory();
write();
}
public void read() {
mode = backingNativeMemory.getInt(0);
angleRanges = backingNativeMemory.getInt(4);
numAngleRanges = backingNativeMemory.getInt(8);
scaleRangeMin = backingNativeMemory.getFloat(12);
scaleRangeMax = backingNativeMemory.getFloat(16);
minMatchScore = backingNativeMemory.getDouble(20);
}
public void write() {
backingNativeMemory.setInt(0, mode);
backingNativeMemory.setInt(4, angleRanges);
backingNativeMemory.setInt(8, numAngleRanges);
backingNativeMemory.setFloat(12, scaleRangeMin);
backingNativeMemory.setFloat(16, scaleRangeMax);
backingNativeMemory.setDouble(20, minMatchScore);
}
public int size() {
return 28;
}
public void free() {
release();
}
}