Package trclib.vision

Class TrcVisionTask<I,O>

java.lang.Object
trclib.vision.TrcVisionTask<I,O>
Type Parameters:
I - specifies the type of the input image.
O - specifies the type of the detected objects.

public class TrcVisionTask<I,O> extends Object
This class implements a platform independent vision task. When enabled, it grabs a frame from the video source, calls the provided vision processor to process the frame and overlays rectangles on the detected objects in the image. This class is to be extended by a platform dependent vision processor.
  • Field Details

    • tracer

      public final TrcDbgTrace tracer
    • instanceName

      private final String instanceName
    • visionProcessor

      private final TrcVisionProcessor<I,O> visionProcessor
    • imageBuffers

      private final I[] imageBuffers
    • visionTaskObj

      private final TrcTaskMgr.TaskObject visionTaskObj
    • detectedObjects

      private final AtomicReference<O[]> detectedObjects
    • taskEnabled

      private volatile boolean taskEnabled
    • imageIndex

      private int imageIndex
    • totalTime

      private double totalTime
    • totalFrames

      private long totalFrames
    • taskStartTime

      private double taskStartTime
  • Constructor Details

    • TrcVisionTask

      public TrcVisionTask(String instanceName, TrcVisionProcessor<I,O> visionProcessor, I[] imageBuffers)
      Constructor: Create an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      visionProcessor - specifies the vision processor object.
      imageBuffers - specifies an array of image buffers.
  • Method Details

    • toString

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

      public void setTaskEnabled(boolean enabled)
      This method enables/disables the vision task. As long as the task is enabled, it will continue to acquire/process images.
      Parameters:
      enabled - specifies true to enable vision task, false to disable.
    • isTaskEnabled

      public boolean isTaskEnabled()
      This method returns the state of the vision task.
      Returns:
      true if the vision task is enabled, false otherwise.
    • 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.
    • getDetectedObjects

      public O[] getDetectedObjects()
      This method returns the last detected objects. Note that this call consumes the objects, meaning if this method is called again before the next frame is finished processing, it will return a null.
      Returns:
      the last detected objects.
    • visionTask

      private void visionTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop)
      This method runs periodically to do vision processing.
      Parameters:
      taskType - specifies the type of task being run.
      runMode - specifies the current robot run mode.
      slowPeriodicLoop - specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.