public class CameraWalker
extends java.lang.Object
The feature detection function will typically process a CvPipeline to detect the feature. It is important that the stages used in the pipeline have no dependencies on any of the aforementioned uncalibrated settings. To aid in the detection, the function is passed a point in image coordinates where the feature is expected to be found and can be used to select the search area and/or mask-off regions of the image that may cause false detections. The function should return either the image coordinates of the feature if it is found or null if the feature could not be found.
The size of each step a CameraWalker takes is normally determined by the distance between the
detected feature image coordinates and its desired image coordinates. That distance is scaled by
the loopGain (defaults to 0.7 but can be changed using the setLoopGain
method) to determine the step size. The maximum size of the steps a CameraWalker takes can be
further limited by using the setMaxAllowedPixelStep
and/or
setMaxAllowedMachineStep
methods.
The walk is considered done when the distance between the detected feature image coordinates and
its desired image coordinates no longer decreases. The walk can also be completed if the detected
feature is within a set distance (in pixels) of the desired image coordinates or if the machine
step is below a set distance (in machine units). These can be set with the
setMinAllowedPixelStep
(defaults to 0) and setMinAllowedMachineStep
(defaults to 0.0001 mm)
methods respectively.
By default, a CameraWalker will only make safe Z moves; however, that behavior can be changed
by using the setOnlySafeZMovesAllowed
method.
Constructor and Description |
---|
CameraWalker(HeadMountable movable,
java.util.function.Function<Point,Point> findFeatureInImage)
Constructs a new CameraWalker with the given parameters
|
Modifier and Type | Method and Description |
---|---|
void |
cancelWalk() |
RealMatrix |
estimateScaling(Length testStepLength,
Point expectedPoint)
Estimates the machine units to pixel scaling by stepping the machine and observing how far
the feature moves in the image.
|
Location |
getDeltaLocation(Point deltaPoint)
Gets an estimate of a change in machine location for a given change in pixels
|
double |
getEstimatedMillimetersPerPixel()
Gets the estimated millimeters per pixel
|
java.util.function.Function<Point,Point> |
getFindFeatureInImage()
Gets the feature detection function
|
java.util.List<double[]> |
getImage2DCoordinates()
Gets the list to which the CameraWalker adds image coordinates as the walk takes place.
|
Location |
getLastFoundLocation()
Gets the machine coordinates at the end of the last walk
|
Point |
getLastFoundPoint()
Gets the image coordinates of the detected feature at the end of the last walk
|
java.lang.Double |
getLoopGain()
Gets the loop gain to be used during the walk
|
java.util.List<double[]> |
getMachine3DCoordinates()
Gets the list to which the CameraWalker adds machine coordinates as the walk takes place.
|
Length |
getMaxAllowedMachineStep()
Gets the maximum allowable step in machine units that the walk can take
|
double |
getMaxAllowedPixelStep()
Gets the maximum allowable step in pixels that the walk can take
|
Length |
getMinAllowedMachineStep()
Gets the minimum allowable step in machine units that the walk can take.
|
double |
getMinAllowedPixelStep()
Gets the minimum allowable step in pixels that the walk can take.
|
double |
getMirror() |
HeadMountable |
getMovable()
Gets the Camera or Nozzle that will do the moving during the walk
|
RealMatrix |
getScalingMat()
Gets the scaling matrix
|
boolean |
isOnlySafeZMovesAllowed()
Checks to see if only safe Z moves are allowed
|
boolean |
isReadyToWalk()
Returns true if the CameraWalker is ready to walk.
|
boolean |
isSingleStep() |
boolean |
isWalkComplete() |
void |
setFindFeatureInImage(java.util.function.Function<Point,Point> findFeatureInImage)
Sets the feature detection function
|
void |
setLoopGain(java.lang.Double loopGain)
Sets the loop gain to be used during the walk, must be greater than 0 and less than or equal
to 1.7 (use caution as very small loop gains may cause walks to take a very long time to
complete and too large may cause unbounded machine oscillations).
|
void |
setMaxAllowedMachineStep(Length maxAllowedMachineStep)
Sets the maximum allowable step in machine units that the walk can take.
|
void |
setMaxAllowedPixelStep(double maxAllowedPixelStep)
Sets the maximum allowable step in pixels that the walk can take.
|
void |
setMinAllowedMachineStep(Length minAllowedMachineStep)
Sets the minimum allowable step in machine units that the walk can take.
|
void |
setMinAllowedPixelStep(double minAllowedPixelStep)
Sets the minimum allowable step in pixels that the walk can take.
|
void |
setMirror(double mirror) |
void |
setMovable(HeadMountable movable)
Sets the Camera or Nozzle that will do the moving during the walk
|
void |
setOnlySafeZMovesAllowed(boolean onlySafeZMovesAllowed)
Sets the only safe Z moves are allowed flag to the given state
|
void |
setSaveCoordinates(java.util.List<double[]> machine3dCoordinates,
java.util.List<double[]> image2dCoordinates)
The CameraWalker will add (save) the coordinates visited during the walk to the lists
provided here.
|
void |
setScalingMat(RealMatrix scalingMat) |
void |
setSingleStep(boolean singleStep) |
boolean |
step() |
Location |
walkToPoint(Location startingMachineLocation,
Point desiredImagePoint)
Iteratively moves the machine in X and Y until the detected feature appears at the desired
image coordinates (or until it is close enough depending on the settings of
minAllowedPixelStep and minAllowedMachineStep).
|
Location |
walkToPoint(Location startingMachineLocation,
Point startingImagePoint,
Point desiredCameraPoint)
Iteratively moves the machine in X and Y until the detected feature appears at the desired
image coordinates (or until it is close enough depending on the settings of
minAllowedPixelStep and minAllowedMachineStep).
|
Location |
walkToPoint(Point desiredImagePoint)
Iteratively moves the machine in X and Y from its current location until the detected feature
appears at the desired image coordinates (or until it is close enough depending on the
settings of minAllowedPixelStep and minAllowedMachineStep).
|
Location |
walkToPoint(Point startingImagePoint,
Point desiredImagePoint)
Iteratively moves the machine in X and Y from its current location until the detected feature
appears at the desired image coordinates (or until it is close enough depending on the
settings of minAllowedPixelStep and minAllowedMachineStep).
|
public CameraWalker(HeadMountable movable, java.util.function.Function<Point,Point> findFeatureInImage)
movable
- - the Camera or Nozzle that will be moved during the walksignedUnitsPerPixelX
- - the signed units per pixel in the X directionsignedUnitsPerPixelY
- - the signed units per pixel in the Y directionfindFeatureInImage
- - the feature detection functionpublic RealMatrix estimateScaling(Length testStepLength, Point expectedPoint) throws java.lang.Exception
testStepLength
- - the distance the machine will step from its current location. This
should be kept relatively small.expectedPoint
- - the expected point where the feature is expected to be detected in
the imagejava.lang.Exception
- if the scaling can't be estimatedpublic boolean isReadyToWalk()
public Location walkToPoint(Location startingMachineLocation, Point desiredImagePoint) throws java.lang.Exception
startingMachineLocation
- - the machine is moved to this location before beginning the
walkdesiredImagePoint
- - the desired image coordinates of the feature when the walk is
completed and is also the expected coordinates of the feature when the machine is at
the starting locationgetLastFoundPoint
java.lang.Exception
public Location walkToPoint(Point desiredImagePoint) throws java.lang.Exception
desiredImagePoint
- - the desired image coordinates of the feature when the walk is
completed and is also the expected coordinates of the feature with the machine at its
current locationgetLastFoundPoint
java.lang.Exception
public Location walkToPoint(Point startingImagePoint, Point desiredImagePoint) throws java.lang.Exception
startingImagePoint
- - the expected image coordinates of the feature with the
machine at its current locationdesiredImagePoint
- - the desired image coordinates of the feature when the walk is
completedgetLastFoundPoint
java.lang.Exception
public Location walkToPoint(Location startingMachineLocation, Point startingImagePoint, Point desiredCameraPoint) throws java.lang.Exception
startingMachineLocation
- - the machine is moved to this location before beginning the
walkstartingImagePoint
- - the expected image coordinates of the feature when the
machine is at the starting locationdesiredCameraPoint
- - the desired image coordinates of the feature when the walk is
completedgetLastFoundPoint
java.lang.Exception
- if the walk can't be started and/or completedpublic boolean step() throws java.lang.Exception
java.lang.Exception
public void cancelWalk()
public boolean isWalkComplete()
public Location getDeltaLocation(Point deltaPoint)
deltaPoint
- - the change in pixelspublic HeadMountable getMovable()
public void setMovable(HeadMountable movable)
public RealMatrix getScalingMat()
public void setScalingMat(RealMatrix scalingMat)
scalingMat
- the scalingMat to setpublic double getMirror()
public void setMirror(double mirror)
mirror
- the mirror to setpublic double getEstimatedMillimetersPerPixel()
public java.util.function.Function<Point,Point> getFindFeatureInImage()
public void setFindFeatureInImage(java.util.function.Function<Point,Point> findFeatureInImage)
public java.lang.Double getLoopGain()
public void setLoopGain(java.lang.Double loopGain)
public double getMaxAllowedPixelStep()
public void setMaxAllowedPixelStep(double maxAllowedPixelStep)
public double getMinAllowedPixelStep()
public void setMinAllowedPixelStep(double minAllowedPixelStep)
public Length getMaxAllowedMachineStep()
public void setMaxAllowedMachineStep(Length maxAllowedMachineStep)
public Length getMinAllowedMachineStep()
public void setMinAllowedMachineStep(Length minAllowedMachineStep)
public boolean isOnlySafeZMovesAllowed()
public void setOnlySafeZMovesAllowed(boolean onlySafeZMovesAllowed)
onlySafeZMovesAllowed
- - the state to setpublic Point getLastFoundPoint()
public Location getLastFoundLocation()
public java.util.List<double[]> getMachine3DCoordinates()
setSaveCoordinates
was not used to set a list to
save the coordinates.public java.util.List<double[]> getImage2DCoordinates()
setSaveCoordinates
was not used to set a list to
save the coordinates.public void setSaveCoordinates(java.util.List<double[]> machine3dCoordinates, java.util.List<double[]> image2dCoordinates)
machine3dCoordinates
- - the list to which the machine coordinates are addedimage2dCoordinates
- - the list to which the image coordinates are addedpublic boolean isSingleStep()
public void setSingleStep(boolean singleStep)
singleStep
- the singleStep to set