IVALab Python Libraries
Collection of code for computer vision and robotics with specific API.
|
Stores and encapsulates a template instance of a visual puzzle piece. More...
Public Member Functions | |
def | __init__ (self, PuzzleTemplate y=None, r=None, id=None, theta=0, pieceStatus=PieceStatus.UNKNOWN) |
Constructor for template class. More... | |
def | deepcopy (self) |
def | displace (self, dr) |
Displace puzzle piece. More... | |
def | display (self, fh=None) |
Display the puzzle piece contents in an image window. More... | |
def | genFeature (self, theMatcher) |
def | getFeature (self, theMatcher=None) |
Get the feature vector of the puzzle piece. More... | |
def | getMask (self, theMask, offset=[0, 0]) |
Get an updated mask of the target. More... | |
def | placeInImage (self, theImage, offset=[0, 0], CONTOUR_DISPLAY=False) |
Insert the puzzle piece into the image in the original location. More... | |
def | placeInImageAt (self, theImage, rc, theta=None, isCenter=False, CONTOUR_DISPLAY=True) |
Insert the puzzle piece into the image at the given location. More... | |
def | replaceSourceData (self, theImage, pOff=None) |
Replace a puzzle pieces source data by grabbing from an image. More... | |
def | rotate (self, theta) |
Rotate piece appearance by given angle. More... | |
def | rotatePiece (self, theta) |
Create copy of puzzle piece instance rotated by the given angle. More... | |
def | setPlacement (self, r, isOffset=False, isCenter=False) |
Provide pixel placement location information. More... | |
def | setStatus (self, theStatus) |
def | size (self) |
Return the dimensions of the puzzle piece image. More... | |
def | toImage (self) |
Return the puzzle piece image (cropped). More... | |
def | update (self, matchedPiece) |
Update template board puzzle piece based on association. More... | |
Static Public Member Functions | |
def | buildFromFullMaskAndImage (theMask, theImage, cLoc=None, rLoc=None, pieceStatus=PieceStatus.MEASURED) |
Given a mask and an image of same base dimensions, use to instantiate a puzzle piece template. More... | |
def | buildFromMaskAndImage (theMask, theImage, cLoc=None, rLoc=None, pieceStatus=PieceStatus.MEASURED) |
Given a mask (individual) and an image of same base dimensions, use to instantiate a puzzle piece template. More... | |
def | buildSphere (radius, color, rLoc=[0, 0]) |
Build a sphere piece. More... | |
def | buildSquare (size, color, rLoc=[0, 0]) |
Build a square piece. More... | |
def | getEig (img) |
To find the major and minor axes of a blob and then return the aligned rotation. More... | |
Public Attributes | |
featVec | |
id | |
lifespan | |
rLoc | |
status | |
theta | |
y | |
Stores and encapsulates a template instance of a visual puzzle piece.
The language here is general, but the fact that it lives in the puzzle.piece namespace indicates that this class is strictly associated to puzzle pieces. As the base class, it probably implements the simplest, no frills version of a template puzzle piece.
def __init__ | ( | self, | |
PuzzleTemplate | y = None , |
||
r = None , |
|||
id = None , |
|||
theta = 0 , |
|||
pieceStatus = PieceStatus.UNKNOWN |
|||
) |
Constructor for template class.
Args: y: The puzzle piece template source data, if given. It is a class instance, see puzzleTemplate. r: The puzzle piece location in the whole image. id: The puzzle piece id in the measured board. Be set up by the board. theta: The puzzle piece aligned angle. pieceStatus: The status of the puzzle pieces, including UNKNOWN, MEASURED, TRACKED, and INHAND.
Reimplemented in Regular.
|
static |
Given a mask and an image of same base dimensions, use to instantiate a puzzle piece template.
This implementation assumes that a whole image and an image-wide mask are provided for recovering a single piece. Then cLoc is not needed. rLoc can still be used.
[in] | theMask | Mask of individual piece. |
[in] | theImage | Source image with puzzle piece. |
[in] | cLoc | Corner location of puzzle piece [optional: None]. |
[in] | rLoc | Alternative puzzle piece location [optional: None]. |
[in] | pieceStatus | Status of the puzzle piece [optional, def:MEASURED] |
[out] | thePiece | Puzzle piece instance. |
|
static |
Given a mask (individual) and an image of same base dimensions, use to instantiate a puzzle piece template.
Passed as cropped mask/image pair.
This can be run in a few different ways. First, assumiong that the puzzle piece has been cropped along with the mask. Then providing cLoc is important for it to be placed in correct part of the original (uncropped) image. If the placement should change for whatever reason, then specifying rLoc will do that. Otherwise, cLoc and rLoc are set to be the same.
[in] | theMask | Mask of individual piece. |
[in] | theImage | Source image with puzzle piece. |
[in] | cLoc | Corner location of puzzle piece [optional: None]. |
[in] | rLoc | Alternative puzzle piece location [optional: None]. |
[in] | pieceStatus | Status of the puzzle piece [optional, def:MEASURED] |
[out] | thePiece | Puzzle piece instance. |
Reimplemented in Regular.
|
static |
Build a sphere piece.
Args: radius: The radius of the sphere. color: (3,). The RGB color. rLoc: (x, y). The puzzle piece location in the whole image. x: left-to-right. y:top-to-down The puzzle piece instance.
Returns: The puzzle piece instance.
|
static |
Build a square piece.
[in] | size | Side length of the square |
[in] | color | The RGB color [size: (3,)] |
[in] | rLoc | Puzzle piece location whole image [(x,y) - x: left-to-right. y:top-to-down] |
def deepcopy | ( | self | ) |
def displace | ( | self, | |
dr | |||
) |
Displace puzzle piece.
[in] | dr | Displacement to apply. |
[in] | isCenter | Boolean flag indicating if r is center reference. |
def display | ( | self, | |
fh = None |
|||
) |
Display the puzzle piece contents in an image window.
Args: fh: The figure label/handle if available. (optional)
Returns: fh: The handle of the image.
def genFeature | ( | self, | |
theMatcher | |||
) |
|
static |
To find the major and minor axes of a blob and then return the aligned rotation.
See https://alyssaq.github.io/2015/computing-the-axes-or-orientation-of-a-blob/ for details. PCA is our default method which does not perform very well.
Args: img: A contour image.
Returns: theta: The aligned angle (degree).
def getFeature | ( | self, | |
theMatcher = None |
|||
) |
Get the feature vector of the puzzle piece.
Assign if not defined based on passed matcher.
[in] | theMatcher | Optional but recommended argument that specifies the feature matching implementation. |
def getMask | ( | self, | |
theMask, | |||
offset = [0, 0] |
|||
) |
Get an updated mask of the target.
[in] | theMask | Original mask of the target. |
[in] | offset | Movement. |
Returns: theMask: The updated mask of the target.
def placeInImage | ( | self, | |
theImage, | |||
offset = [0, 0] , |
|||
CONTOUR_DISPLAY = False |
|||
) |
Insert the puzzle piece into the image in the original location.
[in] | theImage | Source image to put puzzle piece into. |
[in] | offset | Offset coordinates. |
[in] | CONTOUR_DISPLAY | Flag indicating whether to display the contours. |
def placeInImageAt | ( | self, | |
theImage, | |||
rc, | |||
theta = None , |
|||
isCenter = False , |
|||
CONTOUR_DISPLAY = True |
|||
) |
Insert the puzzle piece into the image at the given location.
Args: theImage: The source image to put puzzle piece into. rc: The coordinate location. theta: The orientation of the puzzle piece (default = 0). isCenter: The flag indicating whether the given location is for the center. CONTOUR_DISPLAY: The flag indicating whether to display the contours.
def replaceSourceData | ( | self, | |
theImage, | |||
pOff = None |
|||
) |
Replace a puzzle pieces source data by grabbing from an image.
Takes the template puzzle piece source pixels and uses the image data at those pixel locations to define a new puzzle piece.
[in] | pOff | Offset in (dx,dy) coordinates. |
def rotate | ( | self, | |
theta | |||
) |
Rotate piece appearance by given angle.
[in] | theta | Rotation angle. |
def rotatePiece | ( | self, | |
theta | |||
) |
Create copy of puzzle piece instance rotated by the given angle.
[in] | theta | Rotation angle. |
Reimplemented in Regular.
def setPlacement | ( | self, | |
r, | |||
isOffset = False , |
|||
isCenter = False |
|||
) |
Provide pixel placement location information.
[in] | r | Location of puzzle piece "frame origin." |
[in] | isOffset | Boolean flag indicating whether placement is an offset (= Delta r). |
[in] | isCenter | Boolean flag indicating if r is center reference. |
def setStatus | ( | self, | |
theStatus | |||
) |
def size | ( | self | ) |
Return the dimensions of the puzzle piece image.
Returns: Dimensions of the puzzle piece image
def toImage | ( | self | ) |
Return the puzzle piece image (cropped).
Returns: theImage: The puzzle piece image (cropped).
def update | ( | self, | |
matchedPiece | |||
) |
Update template board puzzle piece based on association.
Performs the simplest of updates.
[in] | matchedPiece | Latest matched measurement of a piece. |
featVec |
id |
lifespan |
rLoc |
status |
theta |
y |