Package trclib.vision
Class TrcOpenCvColorBlobPipeline
java.lang.Object
trclib.vision.TrcOpenCvColorBlobPipeline
- All Implemented Interfaces:
TrcOpenCvPipeline<TrcOpenCvDetector.DetectedObject<?>>
public class TrcOpenCvColorBlobPipeline
extends Object
implements TrcOpenCvPipeline<TrcOpenCvDetector.DetectedObject<?>>
This class implements a generic OpenCV color blob detection pipeline.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis class encapsulates info of the detected object.static classThis class encapsulates all the filter contour parameters. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final doubleprivate static final org.opencv.core.Scalarprivate static final intprivate static final org.opencv.core.Scalarprivate static final org.opencv.core.Scalarprivate booleanprivate final Integerprivate final org.opencv.core.Matprivate final org.opencv.core.Matprivate double[]private final AtomicReference<TrcOpenCvColorBlobPipeline.DetectedObject[]>private final booleanprivate final TrcOpenCvColorBlobPipeline.FilterContourParamsprivate final org.opencv.core.Matprivate final Stringprivate final org.opencv.core.Mat[]private intprivate org.opencv.core.Matprivate final org.opencv.core.Matprivate intprivate TrcVisionPerformanceMetricsfinal TrcDbgTrace -
Constructor Summary
ConstructorsConstructorDescriptionTrcOpenCvColorBlobPipeline(String instanceName, Integer colorConversion, double[] colorThresholds, TrcOpenCvColorBlobPipeline.FilterContourParams filterContourParams, boolean externalContourOnly) Constructor: Create an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidfilterContours(List<org.opencv.core.MatOfPoint> inputContours, TrcOpenCvColorBlobPipeline.FilterContourParams filterContourParams, List<org.opencv.core.MatOfPoint> output) This method filters out contours that do not meet certain criteria.double[]This method returns the color threshold values.This method returns the array of detected objects.org.opencv.core.MatgetIntermediateOutput(int step) This method returns an intermediate processed frame.org.opencv.core.MatThis method returns the selected intermediate output Mat.booleanThis method checks if image annotation is enabled.voidThis method prints the performance metrics to the trace log.process(org.opencv.core.Mat input) This method is called to process the input image through the pipeline.voidreset()This method is called to reset the state of the pipeline if any.voidsetAnnotateEnabled(boolean enabled) This method enables/disables image annotation of the detected object.voidsetColorThresholds(double... colorThresholds) This method sets the color threshold values.voidThis method enables Morphology operation in the pipeline with default kernel shape and size.voidsetMorphologyOp(int morphOp) This method enables Morphology operation in the pipeline with default kernel shape and size.voidsetMorphologyOp(int morphOp, int kernelShape, org.opencv.core.Size kernelSize) This method enables Morphology operation in the pipeline with the specifies kernel shape and size.voidThis method cycles to the next intermediate mat of the pipeline as the video output mat.voidsetPerformanceMetricsEnabled(boolean enabled) This method enables/disables performance metrics.voidsetVideoOutput(int intermediateStep) This method sets the intermediate mat of the pipeline as the video output mat.toString()This method returns the instance name.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface trclib.vision.TrcOpenCvPipeline
annotateFrame
-
Field Details
-
ANNOTATE_RECT_COLOR
private static final org.opencv.core.Scalar ANNOTATE_RECT_COLOR -
ANNOTATE_RECT_WHITE
private static final org.opencv.core.Scalar ANNOTATE_RECT_WHITE -
ANNOTATE_RECT_THICKNESS
private static final int ANNOTATE_RECT_THICKNESS- See Also:
-
ANNOTATE_TEXT_COLOR
private static final org.opencv.core.Scalar ANNOTATE_TEXT_COLOR -
ANNOTATE_FONT_SCALE
private static final double ANNOTATE_FONT_SCALE- See Also:
-
tracer
-
instanceName
-
colorConversion
-
colorThresholds
private double[] colorThresholds -
filterContourParams
-
externalContourOnly
private final boolean externalContourOnly -
colorConversionOutput
private final org.opencv.core.Mat colorConversionOutput -
colorThresholdOutput
private final org.opencv.core.Mat colorThresholdOutput -
morphologyOutput
private final org.opencv.core.Mat morphologyOutput -
hierarchy
private final org.opencv.core.Mat hierarchy -
intermediateMats
private final org.opencv.core.Mat[] intermediateMats -
detectedObjectsUpdate
-
intermediateStep
private int intermediateStep -
annotateEnabled
private boolean annotateEnabled -
morphOp
private int morphOp -
kernelMat
private org.opencv.core.Mat kernelMat -
performanceMetrics
-
-
Constructor Details
-
TrcOpenCvColorBlobPipeline
public TrcOpenCvColorBlobPipeline(String instanceName, Integer colorConversion, double[] colorThresholds, TrcOpenCvColorBlobPipeline.FilterContourParams filterContourParams, boolean externalContourOnly) Constructor: Create an instance of the object.- Parameters:
instanceName- specifies the instance name.colorConversion- specifies color space conversion, can be null if no color space conversion. Note: FTC ECOV input Mat format is RGBA, so you need to do Imgproc.COLOR_RGBA2xxx or Imgproc.COLOR_RGB2xxx conversion. For FRC, the Desktop OpenCV input Mat format is BGRA, so you need to do Imgproc.COLOR_BGRAxxx or Imgproc.COLOR_BGR2xxx conversion.colorThresholds- specifies an array of color thresholds. If color space is RGB, the array contains RGB thresholds (minRed, maxRed, minGreen, maxGreen, minBlue, maxBlue). If color space is HSV, the array contains HSV thresholds (minHue, maxHue, minSat, maxSat, minValue, maxValue).filterContourParams- specifies the parameters for filtering contours, can be null if not provided.externalContourOnly- specifies true for finding external contours only, false otherwise (not applicable if filterContourParams is null).
-
-
Method Details
-
toString
This method returns the instance name. -
setPerformanceMetricsEnabled
public void setPerformanceMetricsEnabled(boolean enabled) This method enables/disables performance metrics.- Parameters:
enabled- specifies true to enable performance metrics, false to disable.
-
printPerformanceMetrics
public void printPerformanceMetrics()This method prints the performance metrics to the trace log. -
getColorThresholds
public double[] getColorThresholds()This method returns the color threshold values.- Returns:
- array of color threshold values.
-
setColorThresholds
public void setColorThresholds(double... colorThresholds) This method sets the color threshold values.- Parameters:
colorThresholds- specifies an array of color threshold values.
-
setMorphologyOp
public void setMorphologyOp(int morphOp, int kernelShape, org.opencv.core.Size kernelSize) This method enables Morphology operation in the pipeline with the specifies kernel shape and size.- Parameters:
morphOp- specifies the Morphology operation.kernelShape- specifies the kernel shape.kernelSize- specifies the kernel size.
-
setMorphologyOp
public void setMorphologyOp(int morphOp) This method enables Morphology operation in the pipeline with default kernel shape and size.- Parameters:
morphOp- specifies the Morphology operation.
-
setMorphologyOp
public void setMorphologyOp()This method enables Morphology operation in the pipeline with default kernel shape and size. -
reset
public void reset()This method is called to reset the state of the pipeline if any.- Specified by:
resetin interfaceTrcOpenCvPipeline<TrcOpenCvDetector.DetectedObject<?>>
-
process
This method is called to process the input image through the pipeline.- Specified by:
processin interfaceTrcOpenCvPipeline<TrcOpenCvDetector.DetectedObject<?>>- Parameters:
input- specifies the input image to be processed.- Returns:
- array of detected objects.
-
getDetectedObjects
This method returns the array of detected objects.- Specified by:
getDetectedObjectsin interfaceTrcOpenCvPipeline<TrcOpenCvDetector.DetectedObject<?>>- Returns:
- array of detected objects.
-
setAnnotateEnabled
public void setAnnotateEnabled(boolean enabled) This method enables/disables image annotation of the detected object.- Specified by:
setAnnotateEnabledin interfaceTrcOpenCvPipeline<TrcOpenCvDetector.DetectedObject<?>>- Parameters:
enabled- specifies true to enable annotation, false to disable.
-
isAnnotateEnabled
public boolean isAnnotateEnabled()This method checks if image annotation is enabled.- Specified by:
isAnnotateEnabledin interfaceTrcOpenCvPipeline<TrcOpenCvDetector.DetectedObject<?>>- Returns:
- true if annotation is enabled, false otherwise.
-
setVideoOutput
public void setVideoOutput(int intermediateStep) This method sets the intermediate mat of the pipeline as the video output mat.- Specified by:
setVideoOutputin interfaceTrcOpenCvPipeline<TrcOpenCvDetector.DetectedObject<?>>- Parameters:
intermediateStep- specifies the intermediate mat used as video output (0 is the original input frame).
-
setNextVideoOutput
public void setNextVideoOutput()This method cycles to the next intermediate mat of the pipeline as the video output mat.- Specified by:
setNextVideoOutputin interfaceTrcOpenCvPipeline<TrcOpenCvDetector.DetectedObject<?>>
-
getIntermediateOutput
public org.opencv.core.Mat getIntermediateOutput(int step) This method returns an intermediate processed frame. Typically, a pipeline processes a frame in a number of steps. It may be useful to see an intermediate frame for a step in the pipeline for tuning or debugging purposes.- Specified by:
getIntermediateOutputin interfaceTrcOpenCvPipeline<TrcOpenCvDetector.DetectedObject<?>>- Parameters:
step- specifies the intermediate step (0 is the original input frame).- Returns:
- processed frame of the specified step.
-
getSelectedOutput
public org.opencv.core.Mat getSelectedOutput()This method returns the selected intermediate output Mat.- Specified by:
getSelectedOutputin interfaceTrcOpenCvPipeline<TrcOpenCvDetector.DetectedObject<?>>- Returns:
- selected output mat.
-
filterContours
private void filterContours(List<org.opencv.core.MatOfPoint> inputContours, TrcOpenCvColorBlobPipeline.FilterContourParams filterContourParams, List<org.opencv.core.MatOfPoint> output) This method filters out contours that do not meet certain criteria.- Parameters:
inputContours- specifies the input list of contours.filterContourParams- specifies the filter contour parameters.output- specifies the the output list of contours.
-