IVALab Python Libraries
Collection of code for computer vision and robotics with specific API.
All Classes Namespaces Files Functions Variables Modules Pages
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Template Class Reference

Stores and encapsulates a template instance of a visual puzzle piece. More...

Inheritance diagram for Template:
Inheritance graph
[legend]

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ __init__()

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.

Member Function Documentation

◆ buildFromFullMaskAndImage()

def buildFromFullMaskAndImage (   theMask,
  theImage,
  cLoc = None,
  rLoc = None,
  pieceStatus = PieceStatus.MEASURED 
)
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.

Parameters
[in]theMaskMask of individual piece.
[in]theImageSource image with puzzle piece.
[in]cLocCorner location of puzzle piece [optional: None].
[in]rLocAlternative puzzle piece location [optional: None].
[in]pieceStatusStatus of the puzzle piece [optional, def:MEASURED]
[out]thePiecePuzzle piece instance.
Todo:
Include option to have cropped mask but full image and use cLoc.

◆ buildFromMaskAndImage()

def buildFromMaskAndImage (   theMask,
  theImage,
  cLoc = None,
  rLoc = None,
  pieceStatus = PieceStatus.MEASURED 
)
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.

Parameters
[in]theMaskMask of individual piece.
[in]theImageSource image with puzzle piece.
[in]cLocCorner location of puzzle piece [optional: None].
[in]rLocAlternative puzzle piece location [optional: None].
[in]pieceStatusStatus of the puzzle piece [optional, def:MEASURED]
[out]thePiecePuzzle piece instance.
Todo:
Include option to have cropped mask but full image and use cLoc.

Reimplemented in Regular.

◆ buildSphere()

def buildSphere (   radius,
  color,
  rLoc = [0,0] 
)
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.

◆ buildSquare()

def buildSquare (   size,
  color,
  rLoc = [0,0] 
)
static

Build a square piece.

Parameters
[in]sizeSide length of the square
[in]colorThe RGB color [size: (3,)]
[in]rLocPuzzle piece location whole image [(x,y) - x: left-to-right. y:top-to-down]
Returns
Puzzle piece instance.

◆ deepcopy()

def deepcopy (   self)

◆ displace()

def displace (   self,
  dr 
)

Displace puzzle piece.

Parameters
[in]drDisplacement to apply.
[in]isCenterBoolean flag indicating if r is center reference.

◆ display()

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.

◆ genFeature()

def genFeature (   self,
  theMatcher 
)

◆ getEig()

def getEig (   img)
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).

◆ getFeature()

def getFeature (   self,
  theMatcher = None 
)

Get the feature vector of the puzzle piece.

Assign if not defined based on passed matcher.

Parameters
[in]theMatcherOptional but recommended argument that specifies the feature matching implementation.

◆ getMask()

def getMask (   self,
  theMask,
  offset = [0, 0] 
)

Get an updated mask of the target.

Parameters
[in]theMaskOriginal mask of the target.
[in]offsetMovement.

Returns: theMask: The updated mask of the target.

◆ placeInImage()

def placeInImage (   self,
  theImage,
  offset = [0, 0],
  CONTOUR_DISPLAY = False 
)

Insert the puzzle piece into the image in the original location.

Parameters
[in]theImageSource image to put puzzle piece into.
[in]offsetOffset coordinates.
[in]CONTOUR_DISPLAYFlag indicating whether to display the contours.

◆ placeInImageAt()

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.

◆ replaceSourceData()

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.

Parameters
[in]pOffOffset in (dx,dy) coordinates.
Returns
newPiece New puzzle template instance.

◆ rotate()

def rotate (   self,
  theta 
)

Rotate piece appearance by given angle.

Parameters
[in]thetaRotation angle.

◆ rotatePiece()

def rotatePiece (   self,
  theta 
)

Create copy of puzzle piece instance rotated by the given angle.

Parameters
[in]thetaRotation angle.
Returns
thePiece Rotated puzzle template instance.

Reimplemented in Regular.

◆ setPlacement()

def setPlacement (   self,
  r,
  isOffset = False,
  isCenter = False 
)

Provide pixel placement location information.

Parameters
[in]rLocation of puzzle piece "frame origin."
[in]isOffsetBoolean flag indicating whether placement is an offset (= Delta r).
[in]isCenterBoolean flag indicating if r is center reference.

◆ setStatus()

def setStatus (   self,
  theStatus 
)

◆ size()

def size (   self)

Return the dimensions of the puzzle piece image.

Returns: Dimensions of the puzzle piece image

◆ toImage()

def toImage (   self)

Return the puzzle piece image (cropped).

Returns: theImage: The puzzle piece image (cropped).

◆ update()

def update (   self,
  matchedPiece 
)

Update template board puzzle piece based on association.

Performs the simplest of updates.

Parameters
[in]matchedPieceLatest matched measurement of a piece.

Member Data Documentation

◆ featVec

featVec

◆ id

id

◆ lifespan

lifespan

◆ rLoc

rLoc

◆ status

status

◆ theta

theta

◆ y

y

The documentation for this class was generated from the following file: