ColourThreshold

abstract class ColourThreshold : Processor<T>

Colour thresholding processor for a colour space, used to find colour contours in an image and to use PnP operations.

This processor serves as an advanced and more feature-rich alternative to the built-in ColourLocator processor, providing more control over the thresholding process and the ability to use PnP (Perspective-N-Point) to determine the real-world position of detected objects.

Author

Lucas Bubner, 2024

Since

6.0.0

See also

Inheritors

Constructors

Link copied to clipboard
constructor()
Creates a new ColourThreshold and auto-adds this class to FtcDashboard.

Types

Link copied to clipboard
The colour spaces that can be used for thresholding.

Properties

Link copied to clipboard
open val cameraMatrix: Mat
Link copied to clipboard
The currently used Colour Space to use for lower and upper thresholds.
Link copied to clipboard
The thickness of the border to draw around the biggest contour.
Link copied to clipboard
Default box colour.
Link copied to clipboard
The thickness of the border to draw around all contours.
Link copied to clipboard
Maximum contour area in percentage to threshold by.
Link copied to clipboard
Minimum contour area in percentage to threshold by.
Link copied to clipboard
@get:NonNull
open val distCoeffs: MatOfDouble
Link copied to clipboard
open var lowerThreshold: Supplier<Scalar>
The currently used lower threshold to apply to filter out contours.
Link copied to clipboard
The used global length of the axes used to display PnP projections (if enabled).
Link copied to clipboard
The used global thickness of the axes used to display PnP projections (if enabled).
Link copied to clipboard
open var upperThreshold: Supplier<Scalar>
The currently used upper threshold to apply to filter out contours.

Inherited properties

Link copied to clipboard
Link copied to clipboard
protected val data: List<T>
List of all vision data detected since the last stateful update.
Link copied to clipboard
open var isFlipped: Boolean
Link copied to clipboard
open val isRunning: Boolean

Functions

Link copied to clipboard
open fun init(@Nullable calibration: CameraCalibration)
Optional method to implement to access the camera calibration data.
Link copied to clipboard
protected fun onFrameDraw(@NonNull canvas: Canvas)
Called by the vision system to draw on the frame.
Link copied to clipboard
protected fun onProcessFrame(@NonNull frame: Mat, captureTimeNanos: Long)
Called by the vision system to process a frame.
Link copied to clipboard
open fun setBiggestContourBorderThickness(staticThicknessPx: Int)
Sets the border thickness of a detected contour that is the largest in the scene.
Link copied to clipboard
open fun setBlurSize(staticBlurSizeUnnormalised: Int)
open fun setBlurSize(@NonNull blurSizeUnnormalised: IntSupplier)
Sets the size of the blur element to use during thresholding.
Link copied to clipboard
open fun setBoxColour(@ColorInt staticColour: Int)
open fun setBoxColour(@NonNull colour: IntSupplier)
Sets the box colour to use for highlighting contours.
Link copied to clipboard
open fun setColourSpace(@NonNull staticColourSpace: ColourThreshold.ColourSpace)
Sets the colour space to use for this ColourThreshold.
Link copied to clipboard
open fun setContourAreaMaxPercent(staticPercent: Double)
Set the upper percentage that will be used as a maximum.
Link copied to clipboard
open fun setContourAreaMinPercent(staticPercent: Double)
Set the lower percentage that will be used as a mininum.
Link copied to clipboard
open fun setContourBorderThickness(staticThicknessPx: Int)
Sets the border thickness of a detected contour that is not the largest in the scene.
Link copied to clipboard
open fun setDilateSize(staticDilateSize: Double)
open fun setDilateSize(@NonNull dilateSize: DoubleSupplier)
Sets the size of the dilating element to use during thresholding.
Link copied to clipboard
open fun setDistCoeffs(k1: Double, k2: Double, p1: Double, p2: Double, k3: Double)
Set the distortion coefficients for the camera.
Link copied to clipboard
open fun setErodeSize(staticErodeSize: Double)
open fun setErodeSize(@NonNull erodeSize: DoubleSupplier)
Sets the size of the eroding element to use during thresholding.
Link copied to clipboard
open fun setExternalContoursOnly(staticUseExternalContours: Boolean)
open fun setExternalContoursOnly(@NonNull useExternalContours: BooleanSupplier)
Filter out contours that are inside other contours.
Link copied to clipboard
open fun setHighlightContourPoints(staticHighlight: Boolean)
Sets whether to highlight the points of the contour on the canvas.
Link copied to clipboard
open fun setLensIntrinsics(fx: Double, fy: Double, cx: Double, cy: Double)
Set the lens intrinsics for the camera.
Link copied to clipboard
open fun setLowerThreshold(@NonNull lower: Supplier<Scalar>)
open fun setLowerThreshold(@NonNull staticLower: Scalar)
Sets the lower scalar to use for thresholding.
Link copied to clipboard
open fun setPnP(@NonNull realWorldObjectWidth: Measure<Distance>, @NonNull realWorldObjectHeight: Measure<Distance>)
Sets the real world dimensions of the object(s) of the thresholded colour to be detected, measured in width and height.
Link copied to clipboard
open fun setRegionOfInterest(@NonNull regionOfInterest: Supplier<ImageRegion>)
open fun setRegionOfInterest(@NonNull staticRegionOfInterest: ImageRegion)
Sets the region of interest for this colour threshold, which will only focus detections on this area.
Link copied to clipboard
open fun setShowMaskedInput(staticShowMaskedInput: Boolean)
open fun setShowMaskedInput(@NonNull showMaskedInput: BooleanSupplier)
Whether to show the colour thresholding on the output mat.
Link copied to clipboard
open fun setUpperThreshold(@NonNull upper: Supplier<Scalar>)
open fun setUpperThreshold(@NonNull staticUpper: Scalar)
Sets the upper scalar to use for thresholding.
Link copied to clipboard
protected fun update()
Called to update new data from the vision system, which involves interpreting, collecting, or otherwise processing new vision data per frame.

Inherited functions

Link copied to clipboard
open fun clearData()
Manually clear the data list.
Link copied to clipboard
open fun delegate(@NonNull delegateTo: Processor)
Delegate this processor to another processor.
Link copied to clipboard
open fun getData(): ArrayList<T>
Get the list of vision data.
Link copied to clipboard
open fun getFrameBitmap(@NonNull continuation: Continuation<out Consumer<Bitmap>>)
abstract fun getFrameBitmap(p: Continuation<out Consumer<Bitmap>>)
Link copied to clipboard
abstract fun getId(): String
Unique identifier for the processor.
Link copied to clipboard
fun init(width: Int, height: Int, @Nullable calibration: CameraCalibration)
abstract fun init(p: Int, p1: Int, p2: CameraCalibration)
Link copied to clipboard
open fun isAttached(): Boolean
Determine whether the processor is attached to a Vision instance or is initialised.
Link copied to clipboard
protected open fun onAttach()
Override this method to run any additional code that will be executed when this processor is attached (via init()) by a Vision instance.
Link copied to clipboard
fun onDrawFrame(@NonNull canvas: Canvas, onscreenWidth: Int, onscreenHeight: Int, scaleBmpPxToCanvasPx: Float, scaleCanvasDensity: Float, @NonNull userContext: Any)
Use onFrameDraw instead, which passes a canvas.
abstract fun onDrawFrame(p: Canvas, p1: Int, p2: Int, p3: Float, p4: Float, p5: Any)
Link copied to clipboard
protected open fun onRunning()
Override this method to run any additional code that will be executed when this processor starts streaming (via start()) on a Vision instance.
Link copied to clipboard
fun processFrame(@NonNull frame: Mat, captureTimeNanos: Long): Any
abstract fun processFrame(p: Mat, p1: Long): Any
Link copied to clipboard