KudanCV
KudanImageTrackable Class Reference

#include <KudanCV.h>

Classes

class  Private
 

Public Member Functions

 KudanImageTrackable (std::shared_ptr< Private >)
 
bool isTrackingReliable ()
 
int isRecovered ()
 
bool isTracked ()
 
KudanVector3 getPosition ()
 
KudanQuaternion getOrientation ()
 
int getNumTrackedPoints ()
 
std::vector< KudanVector2getTrackedPoints ()
 
std::vector< KudanVector2getTrackedCorners ()
 
std::string getName ()
 
void setName (std::string name)
 
float getWidth ()
 
float getHeight ()
 
void setWidth (float width)
 
void setHeight (float height)
 
bool setSize (float width, float height)
 
void setScale (float scale)
 
bool setVirtualCrop (float x, float y, float w, float h)
 
bool resetVirtualCrop ()
 
bool isAutoCropped ()
 
void allowRecoveryMode ()
 
void forceRecoveryMode ()
 
void prohibitRecoveryMode ()
 
bool queryRecoveryMode (bool globalSetting)
 
void setExtensible (bool isExtensible)
 
bool isExtensible ()
 
bool isExtended ()
 
void clearExtensions ()
 

Static Public Member Functions

static std::shared_ptr< KudanImageTrackablecreateFromImageFile (std::string path, std::string name="", bool autoCrop=false)
 
static std::shared_ptr< KudanImageTrackablecreateFromFilePointer (FILE *filePointer)
 
static std::shared_ptr< KudanImageTrackablecreateFromImageData (const unsigned char *imageData, std::string name, int width, int height, int channels, int padding)
 
static std::shared_ptr< KudanImageTrackablecreateFromImageData (const unsigned char *imageData, std::string name, int width, int height, int channels, int padding, bool autoCrop)
 

Friends

class KudanImageTracker
 

Detailed Description

An image which can be tracked. An Image Trackable is a representation of an image which can be detected and tracked by the KudanImageTracker. It stores a representation of the 2D image suitable for tracking, with various other settings (such as its size in pixels). The class will also represent the pose of the tracked image with respect to the camera when tracking is successful, plus other state.

Constructor & Destructor Documentation

◆ KudanImageTrackable()

KudanImageTrackable::KudanImageTrackable ( std::shared_ptr< Private )

This is the only constructor, which cannot be used (because it needs Private data access). Create a KudanImageTrackable using the createFromImageFile (etc) static methods

Member Function Documentation

◆ allowRecoveryMode()

void KudanImageTrackable::allowRecoveryMode ( )

Turn on recovery mode for this Trackable, if enabled. This Trackable can use recover mode if the global setting is switched on (default to global setting). This makes re-detection of previously seen Trackables quicker and possible from a greater range of angles.

◆ clearExtensions()

void KudanImageTrackable::clearExtensions ( )

If this Trackable has any extensions, it will delete them (so they can be re-created). If any of the extensions are being tracked, tracking will immediately fail.

◆ createFromFilePointer()

std::shared_ptr< KudanImageTrackable > KudanImageTrackable::createFromFilePointer ( FILE *  filePointer)
static

Create a new Trackable directly from a file. This is for loading data processed by the Kudan Toolkit in the .KARMarker format, not for reading image files.

Parameters
filePointerA file pointer refering to a .KARMarker file, created with the Kudan Toolkit.
Returns
On success a pointer to the new KudanImageTrackable; a nullptr on fail

◆ createFromImageData()

std::shared_ptr< KudanImageTrackable > KudanImageTrackable::createFromImageData ( const unsigned char *  imageData,
std::string  name,
int  width,
int  height,
int  channels,
int  padding 
)
static

Create a new Trackable from image data. These data should be in the form of a pointer to an unsigned character array. The format of the data must match the specified size and number of channels, otherwise this can cause errors which won't be detected. If Kudan is being used with OpenCV this is easily used with a cv::Mat: createFromImageData(mat.data, "name", mat.size().width, mat.size().height, mat.channels(), 0); In general the image data should be ordered such that the channel c pixel at (x,y) is at position [(width * y + x)*channels + c] (in the same manner as OpenCV)

Parameters
imageDataPointer to the actual image data
nameName of this Trackable
width,height,channels,paddingParameters of the image data
Returns
On success a pointer to the new KudanImageTrackable; a nullptr on fail
Exceptions
KudanExceptionis thrown if the data pointer is null or if a wrong number of channels is given

◆ createFromImageFile()

std::shared_ptr< KudanImageTrackable > KudanImageTrackable::createFromImageFile ( std::string  path,
std::string  name = "",
bool  autoCrop = false 
)
static

Create a new Trackable from an image file. The image is loaded from the specified path, if it exists, and processed to create a Trackable object.

Parameters
pathLocation of th eimage file (jpeg or png)
nameName of this Trackable (optional). If not given, the name is derived from the path
Returns
On success a pointer to the new KudanImageTrackable; a nullptr on fail
Exceptions
KudanExceptionis thrown if the image cannot be read or is empty.

◆ forceRecoveryMode()

void KudanImageTrackable::forceRecoveryMode ( )

Turn on recovery mode for this Trackable. This Trackable will have recovery mode emabled irrespective of the global setting.

◆ getHeight()

float KudanImageTrackable::getHeight ( )

Get the size of the Trackable image with respect to 3D units along its local Y axis. If the size has been set, this affects the height returned.

Returns
The height of the trackable

◆ getName()

std::string KudanImageTrackable::getName ( )

Get the name of this Trackable.

Returns
A string representing the name of this trackable

◆ getNumTrackedPoints()

int KudanImageTrackable::getNumTrackedPoints ( )

Return the number of points used to track this Trackable and estimate its pose. This can be used as a crude way of evaluating how well this Trackable is tracked.

Returns
int A number, representing the number of tracked points.

◆ getOrientation()

KudanQuaternion KudanImageTrackable::getOrientation ( )

Get the 6dof pose of the image Trackable, with respect to the camera. This represents the orientation of the image about its own centre, as a unit quaternion

Returns
a KudanQuaternion which represents a 4D quaternion (x, y, z, w)

◆ getPosition()

KudanVector3 KudanImageTrackable::getPosition ( )

Get the 6dof pose of the image Trackable, with respect to the camera. This represents the position of the centre of the image in 3D in the camera coordinate frame.

Returns
A KudanVector3 which represents a 3D point (x, y, z)

◆ getTrackedCorners()

std::vector< KudanVector2 > KudanImageTrackable::getTrackedCorners ( )

Get a vector of exaclty 4 (or if tracking is not running, zero) points, which are the corners of the tracked region in the camera image

Returns
A vector of 0 or 4 KudanPoints, describing the corners of a quadrilateral in the image

◆ getTrackedPoints()

std::vector< KudanVector2 > KudanImageTrackable::getTrackedPoints ( )

Get a vector of 2D points representing the locations of points on the camera image used for tracking this Trackable. This will have length equivalent to getNumTrackedPoints()

Returns
A vector of KudanPoints, describing points on the current camera image

◆ getWidth()

float KudanImageTrackable::getWidth ( )

Get the size of the Trackable image with respect to 3D units along its local X axis. If the size has been set, this affects the width returned.

Returns
The width of the trackable

◆ isAutoCropped()

bool KudanImageTrackable::isAutoCropped ( )

This returns whether the trackable was automatically cropped or not. Note that even if auto-cropping was requested, it might not have been applied, if it was deemed not to be necessary: this returns whether cropping actually happened. Note also that virtual cropping cannot be applied to an auto-cropped marker

◆ isExtended()

bool KudanImageTrackable::isExtended ( )

Query whether this Trackable has existing extensions or not (i.e. extended tracking and detection was enabled and new Trackables have been created

◆ isExtensible()

bool KudanImageTrackable::isExtensible ( )

Query whether this Trackable can be extended or not (see setExtensible)

◆ isRecovered()

int KudanImageTrackable::isRecovered ( )

Query whether the current tracking state was achieved through recovery-based detection (related to the recovery mode). This returns 0 if detection happened in the usual way, and nonzero if recovery was used (1 indicates recovery re-detection, 2 indicates instant recovery while tracking)

Returns
An integer representing whether recovery was used (1, 2) or not (0)

◆ isTracked()

bool KudanImageTrackable::isTracked ( )

Is this Trackable currently detectd by the image tracker? This is equivalent to asking whether this Trackable will be in the detected Trackables list

Returns
A boolean indicating whether this Trackable was successfully tracked in the most recent process frame.

◆ isTrackingReliable()

bool KudanImageTrackable::isTrackingReliable ( )

Query whether tracking of this Trackable is currently deemed reliable.

Returns
True is tracking is happening in the normal way, false if tracking is not able to use the full matching method

◆ prohibitRecoveryMode()

void KudanImageTrackable::prohibitRecoveryMode ( )

Switch off recovery mode for this Trackable. This prevents this Trackable from using recovery mode, irrespective of the global setting.

◆ queryRecoveryMode()

bool KudanImageTrackable::queryRecoveryMode ( bool  globalSetting)

Query recovery mode for this Trackable. This could depend on the global setting, depending how it was set.

Parameters
globalSettingSpecifies whether recovery mode is allowed in the tracker
Returns
true if recovery mode is enabled for this Trackable, given the Trackable's setting and the global state; otherwise false.

◆ resetVirtualCrop()

bool KudanImageTrackable::resetVirtualCrop ( )

If this trackable has been virtually cropped, this rests it to its initial state. This might not always be possible, e.g. if the trackable has since been extended

Returns
Whether this trackable could be reset to its original size

◆ setExtensible()

void KudanImageTrackable::setExtensible ( bool  isExtensible)

Turn on/off extended detection and tracking for this Trackable. This will allow new Trackables to be automatically created at increasing scales with respect to the original trackable image, to increase the range from which it can be detected and tracked.

Parameters
isExtensibleSet whether extended tracking and detection is on (true) of off (false). If switched on, new trackbles will be automatically created; if switched off, this stops, but extisting extensions will remain (see clearExtensions)

◆ setHeight()

void KudanImageTrackable::setHeight ( float  height)

Set the value which represents the height of this trackable (in the units / reference frame of your choice) This sets what size the trackable will have in the 3D coordinate frame in which its pose is represented. It does not affect tracking.

Parameters
heightThe height of the trackable in some units

◆ setName()

void KudanImageTrackable::setName ( std::string  name)

Set the name on this Trackable. This is stored in the unerlying tracker state and is used to find the correct data (be careful with duplicates)

Parameters
nameThe name which will be assigned to this trackable

◆ setScale()

void KudanImageTrackable::setScale ( float  scale)

Set the scale at which this trackale is represented in the 3D coordinate system. This does not change internal state, and is equivalent to calling setSize. Using setScale(1) will mean the trackable's size is represented in pixel units of the actual trackable image

Parameters
scaleScale factor relating the trackable image size to the apparent size in 3D

◆ setSize()

bool KudanImageTrackable::setSize ( float  width,
float  height 
)

Set the Trackable's size. This might change some graphics but will not change the underlying image or tracking behaviour. It should be used to specify dimensions which make sense for the given Trackable (e.g. real world scale). This will not allow you to change the aspect ratio! Set only to consistent multiplies of the current size (altering the width or height independently does not make sense - this is really a scale factor)

Parameters
width,heightThe dimensions of the Trackable image. These can be in any units, but should always have the same aspect ratio as the actual image.
Exceptions
KudanExceptionis thrown if the Trackable is not initialised or if the width or height are invalid
Returns
A boolean indicating succcess (true) or failure (false) of changing the size

◆ setVirtualCrop()

bool KudanImageTrackable::setVirtualCrop ( float  x,
float  y,
float  w,
float  h 
)

This allows the size of the displayed region to be manually changed, to arbitrary location and size. This does not change the tracking at all, but just the way the result of the tracking is viewed. For example, setting the x and y parameters to 0 and the width and height to 10 will make it appear as though the trackable is a very small square, occupying the top left corner only of the trackable image. Note that the units are the same as those in which the trackable size is expressed in. This means that setting the virtual cropping should be done after specifying the real world size (for example, setting the width to 100 then setting the cropped width to 50 will mean that half of the horizontal size of the trackable will be covered). Some checks are carried out (resulting area must be positive, for example), and there are some limitations (a trackable which is already extended or auto-cropped cannot be re-cropped). The return value will report whether cropping was applied.

Parameters
x,yThe coordinates of the top left corner of the virtual tracked, region in trackable units
w,hThe size of the virtual tracked region, in trackable units
Returns
A boolean indicating whether the virtual cropping was applied successfully.

◆ setWidth()

void KudanImageTrackable::setWidth ( float  width)

Set the value which represents the width of this trackable (in the units / reference frame of your choice) This sets what size the trackable will have in the 3D coordinate frame in which its pose is represented. It does not affect tracking.

Parameters
widthThe width of the trackable in some units

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