Package edu.tufts.hrilab.vision
Class VisionComponent
java.lang.Object
edu.tufts.hrilab.diarc.DiarcComponent
edu.tufts.hrilab.vision.VisionComponent
- All Implemented Interfaces:
VisionInterface
,VisionInterface
DIARC Vision component.
-
Field Summary
Fields inherited from class edu.tufts.hrilab.diarc.DiarcComponent
executionLoopCycleTime, log, shouldRunExecutionLoop
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
addDescriptor
(long typeId, Symbol descriptor) Add new search constraint (i.e., ImageProcessor) to an existing SearchManager (specified by searchID).protected List<org.apache.commons.cli.Option>
Command line options available in sub-class.checkObjAt
(Predicate predicate) boolean
confirmToken
(long tokenId) Confirms that the object is still in STM.boolean
confirmToken
(MemoryObject token) Confirms that the object is still in STM.This instantiates a new MemoryObjecType (search manager) which can be incrementally configured viaaddDescriptor
.void
endDescriptorChanges
(long typeId) Signal the end of constraint addition.protected void
This is where any code that needs to be called repeatedly in a dedicated thread should live.Get List of all SearchManager IDs in long term memory.byte[]
Return the camera's last depth frame in a byte array.getDescriptors
(Long typeId) Get the descriptors for a particular SearchManager.byte[]
Return the camera's last disparity frame in a byte array.byte[]
getFrame()
Return the camera's last frame in a byte array.Returns the size of the image being used.getToken
(long tokenId, double conf) Get the MemoryObject with the specified id.getTokenIds
(double conf) Get MemoryObject IDs in STM with a confidence level over the specified threshold.getTokenIds
(long typeId, double conf) Get MemoryObject IDs that have specified SearchManager ID with a confidence level above the specified threshold.getTokenIds
(List<? extends Symbol> descriptors, double conf) Get MemoryObject IDs for all tokens *exactly* matching descriptors in STM with confidence greater than threshold.getTokens
(double conf) Get MemoryObjects in STM with a confidence over the specified threshold.getTokens
(long typeId, double conf) Get MemoryObjects of the specified SearchManager ID with confidence above specified threshold.Get MemoryObjects *exactly* matching descriptors in STM with confidence greater than threshold.Get the SearchManager ID (search ID) based on a Predicate description of the object.Get the SearchManager ID (search ID) based on a Predicate description of the object.getTypeIds
(double conf) Find all SearchManagers containing at least one token in STM.getUnsatisfiableConstraints
(Symbol descriptor) Find what part(s) of the requested descriptor vision doesn't know how to process.getUnsatisfiableConstraints
(List<? extends Symbol> descriptors) Find what part(s) of the requested descriptors vision doesn't know how to process.protected void
init()
Perform any component initialization.boolean
Use the passed in term to learn a new descriptor.void
loadReferencesFromFile
(String filename) Load pre-defined vision references from file.makeObservations
(Term observation) Entry point in vision for making world observations.boolean
nameDescriptors
(Long typeId, Symbol typeName) Name the collection of Predicate descriptors referred to by the SearchManager ID (search ID).boolean
nameDescriptors
(List<? extends Symbol> descriptors, Symbol typeName) Name the collection of Predicate descriptors.protected void
parseArgs
(org.apache.commons.cli.CommandLine cmdLine) Called directly after construction to pass runtime values that will override default values.void
void
reinitializeVisionComponent
(double camRotX, double camHeight) Should only be used for running component tests to reinitialize capture setting (e.g., use a different image, or camera mode).boolean
removeDescriptor
(long typeId, Symbol descriptor) Remove search constraint (i.e., processing descriptor and/or ImageProcessor) to an existing SearchManager (specified by searchID).void
void
void
sandbox()
void
Any component that needs particular shutdown logic needs to override this method andvoid
startType
(long typeId) Start detecting/tracking specified SearchManager.void
void
stopAndRemoveType
(long typeId) Turns off search for typeId, and removes SearchManager.void
stopType
(long typeId) Stop detecting/tracking specified SearchManager.void
takeSnapshot
(String filename) Save the current frame to file (e.g., for logging).boolean
Un-learns things that have been learned by the learn method.void
writeReferencesToFile
(String filename) Write vision references to file.Methods inherited from class edu.tufts.hrilab.diarc.DiarcComponent
createInstance, createInstance, createInstance, createInstance, getMyGroupConstraints, getMyGroups, getMyService, getMyServices, main, shutdown
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface edu.tufts.hrilab.vision.VisionInterface
getMyGroups
-
Constructor Details
-
VisionComponent
public VisionComponent()
-
-
Method Details
-
init
protected void init()Description copied from class:DiarcComponent
Perform any component initialization. This should not be used for setting local fields to default values as was the case in DIARC. This method is called after the constructor, and after parseArgs. Setting default values should be done in field declaration or in the constructor.- Overrides:
init
in classDiarcComponent
-
reinitializeVisionComponent
public void reinitializeVisionComponent(double camRotX, double camHeight) Should only be used for running component tests to reinitialize capture setting (e.g., use a different image, or camera mode).- Parameters:
camRotX
-camHeight
-
-
executionLoop
protected void executionLoop()Description copied from class:DiarcComponent
This is where any code that needs to be called repeatedly in a dedicated thread should live. It is not called by default and you must set shouldRunExecutionLoop to true in your constructor.- Overrides:
executionLoop
in classDiarcComponent
-
pauseCapture
public void pauseCapture()- Specified by:
pauseCapture
in interfaceVisionInterface
-
resumeCapture
public void resumeCapture()- Specified by:
resumeCapture
in interfaceVisionInterface
-
stopAllSearches
public void stopAllSearches()- Specified by:
stopAllSearches
in interfaceVisionInterface
-
restartAllStoppedSearches
public void restartAllStoppedSearches()- Specified by:
restartAllStoppedSearches
in interfaceVisionInterface
-
shutdownComponent
public void shutdownComponent()Description copied from class:DiarcComponent
Any component that needs particular shutdown logic needs to override this method and- Overrides:
shutdownComponent
in classDiarcComponent
-
additionalUsageInfo
Description copied from class:DiarcComponent
Command line options available in sub-class. This should be paired with a parseArgs implementation.- Overrides:
additionalUsageInfo
in classDiarcComponent
- Returns:
-
parseArgs
protected void parseArgs(org.apache.commons.cli.CommandLine cmdLine) Description copied from class:DiarcComponent
Called directly after construction to pass runtime values that will override default values. This should parse all the options that additionalUsageInfo provides.zs- Overrides:
parseArgs
in classDiarcComponent
-
startType
public void startType(long typeId) Description copied from interface:VisionInterface
Start detecting/tracking specified SearchManager.- Specified by:
startType
in interfaceVisionInterface
-
stopType
public void stopType(long typeId) Description copied from interface:VisionInterface
Stop detecting/tracking specified SearchManager.- Specified by:
stopType
in interfaceVisionInterface
-
stopAndRemoveType
public void stopAndRemoveType(long typeId) Description copied from interface:VisionInterface
Turns off search for typeId, and removes SearchManager.- Specified by:
stopAndRemoveType
in interfaceVisionInterface
-
getAvailableTypeIds
Description copied from interface:VisionInterface
Get List of all SearchManager IDs in long term memory.- Specified by:
getAvailableTypeIds
in interfaceVisionInterface
- Returns:
- List of MemoryObjectType IDs
-
getTypeIds
Description copied from interface:VisionInterface
Find all SearchManagers containing at least one token in STM. One each, regardless of how many tokens of a particular type are in STM.- Specified by:
getTypeIds
in interfaceVisionInterface
- Parameters:
conf
- minimum confidence of tokens to be included- Returns:
- SearchManager IDs
-
getTypeId
Description copied from interface:VisionInterface
Get the SearchManager ID (search ID) based on a Predicate description of the object. The Predicate description must match the SearchManager description exactly. If an existing SearchManager does not match the description, a new SearchManager will be attempted to be built. This assumes that all descriptors refer to the same object. Also starts the SearchManager if not running. NOTE: currently just ignores descriptors that vision doesn't know how to handle.- Specified by:
getTypeId
in interfaceVisionInterface
- Parameters:
descriptors
- Predicate description of object- Returns:
- SearchManager Id (-1 if there is no match)
-
getTypeId
Description copied from interface:VisionInterface
Get the SearchManager ID (search ID) based on a Predicate description of the object. The Predicate description must match the SearchManager description exactly. If a current SearchManager does not match the description a new SearchManager will be attempted to be built. Also starts the SearchManager if not running. NOTE: This is only a convenience method so a List doesn't need to be passed when only a single Predicate is used.- Specified by:
getTypeId
in interfaceVisionInterface
- Parameters:
objectRef
- Predicate description of object- Returns:
- SearchManager Id (-1 if there is no match)
-
nameDescriptors
Description copied from interface:VisionInterface
Name the collection of Predicate descriptors. The descriptors must belong to a single SearchManager that already exists, or an attempt to create a new SearchManager matching the descriptors will be made. The description must match the SearchManager description exactly.- Specified by:
nameDescriptors
in interfaceVisionInterface
- Parameters:
descriptors
- Predicate description of objecttypeName
- Predicate name of object (name will be bound to typeId in VisionComponent)- Returns:
- true if descriptors map to an existing typeId, false otherwise
-
nameDescriptors
Description copied from interface:VisionInterface
Name the collection of Predicate descriptors referred to by the SearchManager ID (search ID).- Specified by:
nameDescriptors
in interfaceVisionInterface
- Parameters:
typeId
- SearchManager ID (search ID)typeName
- Predicate name of object (name will be bound to typeId in VisionComponent)- Returns:
- true if typeId exists, false otherwise
-
getDescriptors
Description copied from interface:VisionInterface
Get the descriptors for a particular SearchManager.- Specified by:
getDescriptors
in interfaceVisionInterface
- Returns:
-
getTokenIds
Description copied from interface:VisionInterface
Get MemoryObject IDs in STM with a confidence level over the specified threshold. Only considers results from SearchManager searches that are currently running.- Specified by:
getTokenIds
in interfaceVisionInterface
- Parameters:
conf
- minimum confidence of tokens to include- Returns:
- List of STM MemoryObject IDs
-
getTokenIds
Description copied from interface:VisionInterface
Get MemoryObject IDs that have specified SearchManager ID with a confidence level above the specified threshold. If the specified SearchManager exists but is not running, it will be started before returning results.- Specified by:
getTokenIds
in interfaceVisionInterface
- Parameters:
typeId
- SearchManager ID of tracked objectsconf
- minimum confidence of tokens to include- Returns:
- List of STM MemoryObject IDs
-
getTokenIds
Description copied from interface:VisionInterface
Get MemoryObject IDs for all tokens *exactly* matching descriptors in STM with confidence greater than threshold. If a matching type is found, it will be started (if not already running). If no match exists, a SearchManager will attempt to be built and started before returning. This is largely a convenience method andgetTypeId
should be used whenever possible.- Specified by:
getTokenIds
in interfaceVisionInterface
- Parameters:
descriptors
- list of Symbol descriptorsconf
- the minimum confidence level- Returns:
- List of STM MemoryObject IDs
-
getTokens
Description copied from interface:VisionInterface
Get MemoryObjects in STM with a confidence over the specified threshold. Only considers results from SearchManager searches that are currently running.- Specified by:
getTokens
in interfaceVisionInterface
- Parameters:
conf
- minimum confidence of tokens to include- Returns:
- List of MemoryObjects
-
getTokens
Description copied from interface:VisionInterface
Get MemoryObjects of the specified SearchManager ID with confidence above specified threshold. If the specified SearchManager exists but is not running, it will be started before returning results.- Specified by:
getTokens
in interfaceVisionInterface
- Parameters:
typeId
- SearchManager ID of tracked objectsconf
- minimum confidence of tokens to include- Returns:
- List of MemoryObjects
-
getTokens
Description copied from interface:VisionInterface
Get MemoryObjects *exactly* matching descriptors in STM with confidence greater than threshold. If a matching type is found, it will be started (if not already running). If no match exists, a SearchManager will attempt to be built and started before returning. This is largely a convenience method andgetTypeId
should be used whenever possible.- Specified by:
getTokens
in interfaceVisionInterface
- Parameters:
descriptors
- list of Symbol descriptorsconf
- the minimum confidence level- Returns:
- List of STM MemoryObjects
-
getToken
Description copied from interface:VisionInterface
Get the MemoryObject with the specified id.- Specified by:
getToken
in interfaceVisionInterface
- Parameters:
tokenId
- MemoryObject ID in STMconf
- minimum confidence of tokens to include- Returns:
- MemoryObject token (Null if doesn't exist)
-
createNewType
Description copied from interface:VisionInterface
This instantiates a new MemoryObjecType (search manager) which can be incrementally configured viaaddDescriptor
.- Specified by:
createNewType
in interfaceVisionInterface
- Returns:
- SearchManager ID (search id)
-
addDescriptor
Description copied from interface:VisionInterface
Add new search constraint (i.e., ImageProcessor) to an existing SearchManager (specified by searchID).- Specified by:
addDescriptor
in interfaceVisionInterface
- Parameters:
typeId
- - unique ID returned bycreateNewType
descriptor
- - predicate describing visual search attribute (e.g., "red", "round")
-
removeDescriptor
Description copied from interface:VisionInterface
Remove search constraint (i.e., processing descriptor and/or ImageProcessor) to an existing SearchManager (specified by searchID).- Specified by:
removeDescriptor
in interfaceVisionInterface
descriptor
- - to remove- Returns:
- - if removal was successful
-
endDescriptorChanges
public void endDescriptorChanges(long typeId) Description copied from interface:VisionInterface
Signal the end of constraint addition. Descriptors/constraints can no longer be added to the SearchManager after this has been called. This also starts the Detector and Tracker and will choose the "object" Detector if one hasn't already been selected.- Specified by:
endDescriptorChanges
in interfaceVisionInterface
-
confirmToken
public boolean confirmToken(long tokenId) Description copied from interface:VisionInterface
Confirms that the object is still in STM.- Specified by:
confirmToken
in interfaceVisionInterface
- Parameters:
tokenId
- MemoryObject ID of the object to be confirmed- Returns:
- true if the MemoryObject is present in STM
-
confirmToken
Description copied from interface:VisionInterface
Confirms that the object is still in STM.- Specified by:
confirmToken
in interfaceVisionInterface
- Parameters:
token
- MemoryObject to be confirmed- Returns:
- true if the object is present in STM
-
takeSnapshot
Description copied from interface:VisionInterface
Save the current frame to file (e.g., for logging).- Specified by:
takeSnapshot
in interfaceVisionInterface
-
getFrame
public byte[] getFrame()Description copied from interface:VisionInterface
Return the camera's last frame in a byte array.- Specified by:
getFrame
in interfaceVisionInterface
- Returns:
- the image in a byte array
-
getDisparityFrame
public byte[] getDisparityFrame()Description copied from interface:VisionInterface
Return the camera's last disparity frame in a byte array.- Specified by:
getDisparityFrame
in interfaceVisionInterface
- Returns:
-
getDepthFrame
public byte[] getDepthFrame()Description copied from interface:VisionInterface
Return the camera's last depth frame in a byte array.- Specified by:
getDepthFrame
in interfaceVisionInterface
- Returns:
-
getImageSize
Description copied from interface:VisionInterface
Returns the size of the image being used.- Specified by:
getImageSize
in interfaceVisionInterface
- Returns:
- Dimension containing the size
-
getUnsatisfiableConstraints
Description copied from interface:VisionInterface
Find what part(s) of the requested descriptors vision doesn't know how to process.- Specified by:
getUnsatisfiableConstraints
in interfaceVisionInterface
- Returns:
- list of (possibly empty) unsatisfiable constraints
-
getUnsatisfiableConstraints
Description copied from interface:VisionInterface
Find what part(s) of the requested descriptor vision doesn't know how to process.- Specified by:
getUnsatisfiableConstraints
in interfaceVisionInterface
- Returns:
- list of (possibly empty) unsatisfiable constraints
-
learn
Description copied from interface:VisionInterface
Use the passed in term to learn a new descriptor. The term must have two arguments, the first arg 'describing' the new thing-to-learn, and the second arg 'naming' the new thing-to-learn. The description must be composed entirely of things vision already knows about.- Specified by:
learn
in interfaceVisionInterface
- Parameters:
learningTerm
- term specifying the kind of learning to do (e.g., instanceOf(X,Y), definitionOf(X,Y))bindings
- variable bindings to any variables in query term- Returns:
- if thing-to-learn was successfully learned
-
unlearn
Description copied from interface:VisionInterface
Un-learns things that have been learned by the learn method.- Specified by:
unlearn
in interfaceVisionInterface
- Returns:
-
makeObservations
Description copied from interface:VisionInterface
Entry point in vision for making world observations.- Specified by:
makeObservations
in interfaceVisionInterface
- Parameters:
observation
- single term specifying observation to make- Returns:
- bindings for any free variables in observation term
-
writeReferencesToFile
Write vision references to file.- Parameters:
filename
-
-
loadReferencesFromFile
Load pre-defined vision references from file.- Parameters:
filename
-
-
sandbox
public void sandbox() -
checkObjAt
-