Class VisionProcess<T extends Enum<T>,Detail extends VisionProcessDetail<T>,NVP extends NativeVisionProcess>

java.lang.Object
edu.tufts.hrilab.vision.visionproc.VisionProcess<T,Detail,NVP>
Type Parameters:
T - SWIG wrapped enum class (ImageProcessorType, DetectorType,
Detail -
NVP -
Direct Known Subclasses:
Detector, ImageProcessor, Learner, Tracker

public abstract class VisionProcess<T extends Enum<T>,Detail extends VisionProcessDetail<T>,NVP extends NativeVisionProcess> extends Object
Base class for Detector, Tracker, and ImageProcessor classes. ============ IMPORTANT ==================== (1) terminate() must be called when a VisionProcess is no longer used. (2) Every public class method must be synchronized and call isValid() at the beginning of the method. ===========================================
  • Field Details

    • log

      protected org.slf4j.Logger log
      Log4j logger.
    • id_generator

      protected static final IdGenerator id_generator
      To generate unique IDs for each VisionProcessor.
    • processId

      protected final long processId
      Unique processor ID.
    • detail

      protected final Detail extends VisionProcessDetail<T> detail
      Basic information about how to instantiate a particular kind of Vision Processor.
    • dependencies

      protected HashMap<ImageProcessorType,ImageProcessor> dependencies
      Processor's image processing dependencies (e.g. sift, etc).
    • processor

      protected final NVP extends NativeVisionProcess processor
      Native processor (used via SWIG) that does the actual vision processing work.
    • runFlag

      protected volatile boolean runFlag
      If this processor is currently running.
    • description

      protected HashMap<Object,List<Term>> description
      Predicate description that processor is trying to process. Hashed by caller object.
    • performanceInfo

      protected TaskPerformanceInformation performanceInfo
      Runtime stats and metrics.
    • singleIteration

      protected boolean singleIteration
      If true, only complete one processing iteration and then stop.
  • Constructor Details

    • VisionProcess

      public VisionProcess(Detail typeDetail, NVP nativeProcessor)
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getId

      public final long getId()
      Get ID of vision processor.
      Returns:
      processor Id
    • isType

      public boolean isType(T processType)
      Check if VisionProcess is of certain enum type.
      Parameters:
      processType - - enum Type.
      Returns:
    • getType

      public T getType()
      Get VisionProcess enum Type
      Returns:
    • getNativeProcessor

      public NVP getNativeProcessor()
      Get underlying native VisionProcess. Mainly used to register processors with each other.
      Returns:
    • getPerformanceInfo

      public TaskPerformanceInformation getPerformanceInfo()
      Get performance info for introspection tasks.
      Returns:
    • getDependencies

      public List<ImageProcessorType> getDependencies()
      Get ImageProcessor dependencies.
      Returns:
    • getDependency

      public ImageProcessor getDependency(ImageProcessorType type)
      Get specific instantiated ImageProcessor dependency. Null if dependency doesn't exist.
      Parameters:
      type -
      Returns:
    • loadConfig

      public void loadConfig(String config)
      Configure native VisionProcess.
      Parameters:
      config - filename
    • registerForNotification

      public void registerForNotification(VisionProcess processor, Long typeId)
      Register a VisionProcess to be interrupted or notified every time a "perform" iteration has been completed. The notification is sent and received on that native side.
      Parameters:
      processor - to be notified.
    • unregisterForNotification

      public void unregisterForNotification(VisionProcess processor, Long typeId)
      Unregister a previously registered VisionProcess to no longer be notified.
      Parameters:
      processor - to be notified.
    • getRegisteredProcessorIds

      public List<Long> getRegisteredProcessorIds(Long typeId)
    • registerForCaptureNotification

      public void registerForCaptureNotification()
      Register to be notified every time a "capture" iteration has been completed. The notification is sent and received on that native side. This method is needed because the capture processor does not derive from the VisionProccess base class.
    • unregisterForCaptureNotification

      public void unregisterForCaptureNotification()
      Un-register from the "capture" notifications. This method is needed because the capture processor does not derive from the VisionProccess base class.
    • addProcessingDescriptor

      public final boolean addProcessingDescriptor(Term descriptor, SearchManager caller)
      Add descriptor to VisionProcess (e.g., add "red" to color processor)
      Parameters:
      descriptor - - Predicate to add
      caller - - the object adding the descriptor (almost always a SearchManager)
      Returns:
      - if add was successful
    • addProcessingDescriptorToNative

      protected boolean addProcessingDescriptorToNative(Term descriptor, Long callerId)
      Add descriptor to native VisionProcess. This is a separate method so it can be overridden in super classes.
      Parameters:
      descriptor - - to add to native side
      Returns:
      if addition was successful
    • removeProcessingDescriptor

      public final boolean removeProcessingDescriptor(Term descriptor, SearchManager caller)
      Remove descriptor to VisionProcess (e.g., remove "red" from color processor)
      Parameters:
      descriptor - - Predicate to remove
      caller - - the object removing the descriptor (almost always a SearchManager)
      Returns:
      - if removal was successful
    • removeProcessingDescriptorFromNative

      protected boolean removeProcessingDescriptorFromNative(Term descriptor, Long callerId)
      Remove descriptor from native VisionProcess. This is a separate method so it can be overridden in super classes.
      Parameters:
      descriptor - - to remove from native side
      Returns:
      if addition was successful
    • getProcessingDescriptors

      public List<Term> getProcessingDescriptors(Object caller)
    • parsePredicate

      public String parsePredicate(Term descriptor)
      Parse predicate for appropriate descriptor to send to C++ processor. Detectors, ImageProcessors, etc, should override this method if it's not general enough.
      Parameters:
      descriptor -
      Returns:
    • getProcessingDescriptorsSize

      public int getProcessingDescriptorsSize()
      Get the number of processing descriptors.
      Returns:
    • hasLearned

      public boolean hasLearned()
      Check if underlying native vision processor has learned.
      Returns:
    • resetHasLearned

      public void resetHasLearned()
      Reset underlying native vision processor's has learned flag, so that learning can happen repeatedly.
    • getDisplayFlag

      public boolean getDisplayFlag()
      Get whether or not VisionProcess display flag is set.
      Returns:
    • setDisplayFlag

      public void setDisplayFlag(boolean flag)
      Turn on VisionProcess display.
      Parameters:
      flag -
    • getIncrementalProcessing

      public boolean getIncrementalProcessing()
      Get incremental processing flag.
      Returns:
    • setIncrementalProcessing

      public void setIncrementalProcessing(boolean flag)
      Turn on/off incremental processing.
      Parameters:
      flag -
    • getSerialProcessing

      public boolean getSerialProcessing()
      Get serial processing flag.
      Returns:
    • setSerialProcessing

      public void setSerialProcessing(boolean flag)
      Turn on/off serial processing.
      Parameters:
      flag -
    • getSingleIteration

      public boolean getSingleIteration()
      Get single iteration flag.
      Returns:
    • setSingleIteration

      public void setSingleIteration(boolean flag)
      Turn on/off single iteration processing.
      Parameters:
      flag -
    • isRunning

      public boolean isRunning()
      Is VisionProcess running.
      Returns:
    • isStartCaller

      public boolean isStartCaller(Object caller)
      Check if caller has called start on this VisionProcessor.
      Returns:
    • start

      public void start(Object caller)
      Run VisionProcess.
      Parameters:
      caller -
    • stop

      public void stop(Object caller, boolean wait)
      Stop running VisionProcess and destroy native data.
      Parameters:
      caller -
      wait - If method should wait on stop to complete or return immediately.
    • terminate

      protected void terminate()
      This method must be called when a VisionProcess is "deleted" so that its ImageProcessor dependencies (if any) can be "freed" from the AvailableImageProcessors factory. An VisionProcess is no longer valid after this method is called.
    • isValid

      protected void isValid()
      Every public class method, even subclass methods, needs to call this to ensure that terminate has not been called.
    • perform

      protected abstract void perform()
      Main processing method to be written by sub-class.