Functions to convert between Vision Space & World Space

Vision Space vs. World Space: context

Vision Space:
Vision Space is an integer lattice space (only integer values allowed) with origin in the upper left-hand corner. Right is the positive x-direction and down is the positive y-direction. Typically the dimension of this space is in sensor pixels, and the extents match the resolution of the image generator's (e.g. camera's) output signal, for instance 320x240.

World Space:
World Space is a floating-point plane (decimals allowed) with origin in the center of the world. Right is the positive x-direction, up is the positive y-direction. The unit dimension of the space is user specifiable (default 2x2).

See also: All About Coordinate Spaces
See also: OpenCV Data Structures

Functions:

point: vision space > world space
CvPoint2D32f VisionInput::xformPointToWorld(CvPoint2D32f point, float worldWidth, float worldHeight)
CvPoint2D32f VisionInput::xformPointToWorld(CvPoint point, float worldWidth, float worldHeight)
CvPoint2D32f VisionInput::xformPointToWorld(float x, float y, float worldWidth, float worldHeight)

    #python
    humans = playmotion.getHumans()
    person = humans[0]
    head = playmotion.xformPointToWorld(person.head, 
                                        base.getAspectRatio()*2,
                                        2)
    

This transforms the x,y scale/direction and origin of a point from vision space to world space of unit height 2, width dependent on aspect ratio.

point: world space > vision space
CvPoint VisionInput::xformPointToSegmentation(CvPoint2D32f point, float worldWidth, float worldHeight)
CvPoint VisionInput::xformPointToSegmentation(CvPoint point, float worldWidth, float worldHeight)
CvPoint VisionInput::xformPointToSegmentation(float x, float y, float worldWidth, float worldHeight)

This transforms the x,y scale/direction and origin of a point from world space to vision space .

vector: vision space > world space
CvPoint2D32f VisionInput::xformVectorToWorld(CvPoint2D32f point, float worldWidth, float worldHeight)
CvPoint2D32f VisionInput::xformVectorToWorld(CvPoint point, float worldWidth, float worldHeight)
CvPoint2D32f VisionInput::xformVectorToWorld(float x, float y, float worldWidth, float worldHeight)

This transforms the x,y scale/direction of a vector from vision space to world space

vector: world space > vision space
CvPoint2D32f VisionInput::xformVectorToSegmentation(CvPoint2D32f point, float worldWidth, float worldHeight)
CvPoint2D32f VisionInput::xformVectorToSegmentation(CvPoint point, float worldWidth, float worldHeight)
CvPoint2D32f VisionInput::xformVectorToSegmentation(float x, float y, float worldWidth, float worldHeight)

This transforms the x,y scale/direction of a vector from world space to vision space.

scalar: vision space > world space
float VisionInput::xformScalarToWorld(float val, float worldWidth, float worldHeight)
This transforms the scale of a scalar from vision space to world space.

scalar: world space > vision space
float VisionInput::xformScalarToSegmentation(float val, float worldWidth, float worldHeight)
This transforms the scale of a scalar from world space to vision space.

normalize vector
CvPoint2D32f VisionInput::normalizeVector(CvPoint2D32f point)
CvPoint2D32f VisionInput::normalizeVector(float x, float y)
void VisionInput::normalizeVector(float* x, float* y)

This normalizes a vector (make of length 1.0, unless it is the vector (0.0,0.0) ).