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 Summary
FieldsModifier and TypeFieldDescriptionprotected HashMap<ImageProcessorType,
ImageProcessor> Processor's image processing dependencies (e.g.Predicate description that processor is trying to process.protected final Detail
Basic information about how to instantiate a particular kind of Vision Processor.protected static final IdGenerator
To generate unique IDs for each VisionProcessor.protected org.slf4j.Logger
Log4j logger.protected TaskPerformanceInformation
Runtime stats and metrics.protected final long
Unique processor ID.protected final NVP
Native processor (used via SWIG) that does the actual vision processing work.protected boolean
If this processor is currently running.protected boolean
If true, only complete one processing iteration and then stop. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
addProcessingDescriptor
(Term descriptor, SearchManager caller) Add descriptor to VisionProcess (e.g., add "red" to color processor)protected boolean
addProcessingDescriptorToNative
(Term descriptor, Long callerId) Add descriptor to native VisionProcess.Get ImageProcessor dependencies.Get specific instantiated ImageProcessor dependency.boolean
Get whether or not VisionProcess display flag is set.final long
getId()
Get ID of vision processor.boolean
Get incremental processing flag.Get underlying native VisionProcess.Get performance info for introspection tasks.getProcessingDescriptors
(Object caller) int
Get the number of processing descriptors.getRegisteredProcessorIds
(Long typeId) boolean
Get serial processing flag.boolean
Get single iteration flag.getType()
Get VisionProcess enum Typeboolean
Check if underlying native vision processor has learned.boolean
Is VisionProcess running.boolean
isStartCaller
(Object caller) Check if caller has called start on this VisionProcessor.boolean
Check if VisionProcess is of certain enum type.protected void
isValid()
Every public class method, even subclass methods, needs to call this to ensure thatterminate
has not been called.void
loadConfig
(String config) Configure native VisionProcess.parsePredicate
(Term descriptor) Parse predicate for appropriate descriptor to send to C++ processor.protected abstract void
perform()
Main processing method to be written by sub-class.void
Register to be notified every time a "capture" iteration has been completed.void
registerForNotification
(VisionProcess processor, Long typeId) Register a VisionProcess to be interrupted or notified every time a "perform" iteration has been completed.final boolean
removeProcessingDescriptor
(Term descriptor, SearchManager caller) Remove descriptor to VisionProcess (e.g., remove "red" from color processor)protected boolean
removeProcessingDescriptorFromNative
(Term descriptor, Long callerId) Remove descriptor from native VisionProcess.void
Reset underlying native vision processor's has learned flag, so that learning can happen repeatedly.void
setDisplayFlag
(boolean flag) Turn on VisionProcess display.void
setIncrementalProcessing
(boolean flag) Turn on/off incremental processing.void
setSerialProcessing
(boolean flag) Turn on/off serial processing.void
setSingleIteration
(boolean flag) Turn on/off single iteration processing.void
Run VisionProcess.void
Stop running VisionProcess and destroy native data.protected void
This method must be called when a VisionProcess is "deleted" so that its ImageProcessor dependencies (if any) can be "freed" from the AvailableImageProcessors factory.toString()
void
Un-register from the "capture" notifications.void
unregisterForNotification
(VisionProcess processor, Long typeId) Unregister a previously registered VisionProcess to no longer be notified.
-
Field Details
-
log
protected org.slf4j.Logger logLog4j logger. -
id_generator
To generate unique IDs for each VisionProcessor. -
processId
protected final long processIdUnique processor ID. -
detail
Basic information about how to instantiate a particular kind of Vision Processor. -
dependencies
Processor's image processing dependencies (e.g. sift, etc). -
processor
Native processor (used via SWIG) that does the actual vision processing work. -
runFlag
protected volatile boolean runFlagIf this processor is currently running. -
description
Predicate description that processor is trying to process. Hashed by caller object. -
performanceInfo
Runtime stats and metrics. -
singleIteration
protected boolean singleIterationIf true, only complete one processing iteration and then stop.
-
-
Constructor Details
-
VisionProcess
-
-
Method Details
-
toString
-
getId
public final long getId()Get ID of vision processor.- Returns:
- processor Id
-
isType
Check if VisionProcess is of certain enum type.- Parameters:
processType
- - enum Type.- Returns:
-
getType
Get VisionProcess enum Type- Returns:
-
getNativeProcessor
Get underlying native VisionProcess. Mainly used to register processors with each other.- Returns:
-
getPerformanceInfo
Get performance info for introspection tasks.- Returns:
-
getDependencies
Get ImageProcessor dependencies.- Returns:
-
getDependency
Get specific instantiated ImageProcessor dependency. Null if dependency doesn't exist.- Parameters:
type
-- Returns:
-
loadConfig
Configure native VisionProcess.- Parameters:
config
- filename
-
registerForNotification
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
Unregister a previously registered VisionProcess to no longer be notified.- Parameters:
processor
- to be notified.
-
getRegisteredProcessorIds
-
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
Add descriptor to VisionProcess (e.g., add "red" to color processor)- Parameters:
descriptor
- - Predicate to addcaller
- - the object adding the descriptor (almost always a SearchManager)- Returns:
- - if add was successful
-
addProcessingDescriptorToNative
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
Remove descriptor to VisionProcess (e.g., remove "red" from color processor)- Parameters:
descriptor
- - Predicate to removecaller
- - the object removing the descriptor (almost always a SearchManager)- Returns:
- - if removal was successful
-
removeProcessingDescriptorFromNative
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
-
parsePredicate
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
Check if caller has called start on this VisionProcessor.- Returns:
-
start
Run VisionProcess.- Parameters:
caller
-
-
stop
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 thatterminate
has not been called. -
perform
protected abstract void perform()Main processing method to be written by sub-class.
-