Package trclib.vision

Class TrcOpenCvDetector

java.lang.Object
trclib.vision.TrcOpenCvDetector
All Implemented Interfaces:
TrcVideoSource<org.opencv.core.Mat>, TrcVisionProcessor<org.opencv.core.Mat,TrcOpenCvDetector.DetectedObject<?>>
Direct Known Subclasses:
TrcOpenCvFaceDetector

public abstract class TrcOpenCvDetector extends Object implements TrcVisionProcessor<org.opencv.core.Mat,TrcOpenCvDetector.DetectedObject<?>>
This class implements a generic OpenCV detector. Typically, it is extended by a specific detector that provides the pipeline to process an image for detecting objects using OpenCV APIs.
  • Field Details

  • Constructor Details

    • TrcOpenCvDetector

      public TrcOpenCvDetector(String instanceName, int numImageBuffers, TrcHomographyMapper.Rectangle cameraRect, TrcHomographyMapper.Rectangle worldRect)
      Constructor: Create an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      numImageBuffers - specifies the number of image buffers to allocate.
      cameraRect - specifies the camera rectangle for Homography Mapper, can be null if not provided.
      worldRect - specifies the world rectangle for Homography Mapper, can be null if not provided.
  • Method Details

    • toString

      public String toString()
      This method returns the instance name.
      Overrides:
      toString in class Object
      Returns:
      instance name.
    • setProcessingInterval

      public void setProcessingInterval(long interval)
      This method sets the vision task processing interval.
      Parameters:
      interval - specifies the processing interval in msec. If 0, process as fast as the CPU can run.
    • getProcessingInterval

      public long getProcessingInterval()
      This method returns the vision task processing interval.
      Returns:
      vision task processing interval in msec.
    • setPipeline

      public void setPipeline(TrcOpenCvPipeline<TrcOpenCvDetector.DetectedObject<?>> pipeline)
      This method sets the OpenCV pipeline to be used for the detection and enables it.
      Parameters:
      pipeline - specifies the pipeline to be used for detection, can be null to disable vision.
    • getPipeline

      This method returns the current pipeline.
      Returns:
      current pipeline, null if no set pipeline.
    • getDetectedTargetsInfo

      public TrcVisionTargetInfo<TrcOpenCvDetector.DetectedObject<?>>[] getDetectedTargetsInfo(TrcOpenCvDetector.FilterTarget filter, Comparator<? super TrcVisionTargetInfo<TrcOpenCvDetector.DetectedObject<?>>> comparator, double objGroundOffset, double cameraHeight)
      This method returns an array of detected targets from Grip vision.
      Parameters:
      filter - specifies the filter to call to filter out false positive targets.
      comparator - specifies the comparator to sort the array if provided, can be null if not provided.
      objGroundOffset - specifies the object ground offset above the floor.
      cameraHeight - specifies the height of the camera above the floor.
      Returns:
      array of detected target info.
    • processFrame

      public TrcOpenCvDetector.DetectedObject<?>[] processFrame(org.opencv.core.Mat input)
      This method is called to detect objects in the acquired image frame.
      Specified by:
      processFrame in interface TrcVisionProcessor<org.opencv.core.Mat,TrcOpenCvDetector.DetectedObject<?>>
      Parameters:
      input - specifies the image to be processed.
      Returns:
      detected objects, null if none detected.
    • getSelectedOutput

      public org.opencv.core.Mat getSelectedOutput()
      This method returns the selected intermediate output Mat.
      Specified by:
      getSelectedOutput in interface TrcVisionProcessor<org.opencv.core.Mat,TrcOpenCvDetector.DetectedObject<?>>
      Returns:
      selected output mat.