Vizard 7 » Reference » Input Devices » Position and Orientation Trackers » ARToolKit
7.6

ARToolKit plug-in

This plug-in provides support for the ARToolKit library.

Resources

Vizard comes with sample ARToolKit pattern files. They are located in the \resources\ar directory of your Vizard installation folder. You can use the PDF files to print the patterns onto a sheet of paper. You then use the corresponding patt.* file when creating a marker object with the addMarker(...) function below.

 

ARToolKit also supports matrix based markers, instead of image based markers. There are 64 unique matrix markers and they are specified by an ID number between 0-63. You can visit this ARToolKit page and download a matrix pattern to print out. In your script you will use the addMatrixMarker(...) function to specify the matrix ID when creating a marker.

Initialization

The ARToolKit plug-in is implemented as a Vizard extension. Once the ARToolKit extension is added, the following methods/constants are available on the extension object:

Method

Description

<ar>.addCamera(texture,

                       param=None,

                       flipVertical=False,

                       thresh=None,

                       globalScale=None,

                       window=viz.MainWindow)

Create an ARCamera object from the specified texture argument. The texture is usually a video camera texture, but it can be any standard texture object.

 

You can optionally specify a camera parameter file using the param argument. If not specified, a default calibration will be used. Camera parameter files do not need to be used for video see through applications.

 

By default, it is assumed the camera texture data starts at the lower left corner of the image. If the image data starts at the upper left corner then set the flipVertical argument to True.

 

You can specify the processing threshold to use for detecting markers using the thresh argument.

 

The window argument controls which window to draw the camera image into. Set to None, if you do not want to render the image.

<ar>.addWebCamera( size=[640,480] , **kw )

This is a helper function that will automatically use the VideoCamera.dle extension to connect to the first available web camera at the specified size. It will then call the addCamera(...) function above with the optional keyword arguments and return the ARCamera object.

<ar>.MARKER_GLOBAL

<ar>.MARKER_LOCAL

Flags that can be used when retrieving the position/rotation of individual markers of a multi-marker pattern.

The ARCamera object is a standard extension sensor with the following methods:

Method

Description

<camera>.addMarker(pattern,

                             width=None,

                             smoothing=None)

Creates an ARMarker sensor from the specified ARToolKit pattern file. Can optionally specify the width and smoothing value of the marker, or use default values if not specified.

<camera>.addMultiMarker(pattern,

                                   width=None,

                                   smoothing=None)

Creates an ARMultiMarker sensor from the specified ARToolKit multi-marker pattern file. Can optionally specify the width and smoothing value of the marker, or use default values if not specified.

<camera>.addMatrixMarker(id,

                                     width=None,

                                     smoothing=None)

Creates an ARMarker sensor using the specified ARToolKit matrix ID. Can optionally specify the width and smoothing value of the marker, or use default values if not specified.

<camera>.setThresh(thresh)

Specifies the threshold value (between 0-255) to be used to convert the input image into a binary image. Default is 100.

<camera>.getThresh()

Returns the current threshold value of the camera.

<camera>.setDebug(mode)

Controls whether camera debugging is enabled. Can be True or False. When debugging is enabled, the camera image will be converted to black and white using the current threshold. This is useful when trying to adjust the threshold value to the current lighting conditions.

<camera>.getDebug()

Returns whether debug is enabled.

<camera>.setGlobalScale(scale)

Set the global scale factor for all the markers of the camera. The scale factor is used in conjunction with the markers width. A larger scale factor will cause all marker positions to be computed further from the camera, which will make the geometry look smaller. The default scale is 1.0

<camera>.getGlobalScale()

Returns the global scale factor of the camera.

<camera>.getTimeStamp()

Get time of last camera update. Based on viz.tick() value.

<camera>.getProjectionMatrix(near=0.1,far=100.0)

Returns the projection matrix of the camera, using specified near/far clip planes.

<camera>.distortVertex(v)

Converts undistorted [x,y] camera pixel coordinates to distorted pixel coordinates.

<camera>.undistortVertex(v)

Converts distorted [x,y] camera pixel coordinates to undistorted pixel coordinates.

<camera>.drawInWindow(window,meshSize=20)

Renders the camera texture as the background of the specified window. This will create a mesh that accounts for the camera distortion and applies the camera texture to it. This function will also apply the camera projection matrix to the window and link the camera to the windows viewpoint. The meshSize argument controls the width and height of the distortion grid.

<camera>.setMatrix(matrix)

Set the fixed matrix transform of the camera. All marker positions will be reported relative to this transform. The default camera matrix is the identity matrix.

<camera>.setGlobalMarker(marker,

                                    matrix=viz.Matrix() )

Specify a marker that can be used by the camera to determine its global position. The optional matrix parameter specifies the global matrix transform of the marker, defaulting to an identity matrix. When a global marker is specified the position/rotation of the camera will be automatically updated every frame. Only one global marker can be active at any time per camera. If None is specified for the marker parameter, then the current global marker will be deactivated.

<camera>.getRawMarkers()

Returns a list of raw marker objects detected during the last update. Raw marker objects contain the following attributes:

 

marker - The marker sensor that the raw marker belongs to. None if it does not belong to an existing sensor.

 

area - The 2D pixel area of the raw marker in the image.

 

cf - The confidence value of the raw marker if it belongs to an existing sensor.

 

vertex - A list of 2D vertices representing the location of each corner of the marker in the camera image. The vertex positions have distortion correction applied to them.

<camera>.getRawMarkerMatrix(rawMarker,width=80.0)

Returns the transform matrix of the given rawMarker object with the specified width, in millimeters.

<camera>.savePattern(filename,rawMarker)

Create a new pattern file with the given filename from the specified rawMarker object.

The ARMarker object is a standard extension sensor that provides 6DOF data. The position/rotation data is relative to the video camera. The ARMarker has the following methods in addition to the standard extension sensor methods:

Method

Description

<marker>.setWidth(mm)

Specifies the physical width of the marker pattern in millimeters. Default is 80

<marker>.getWidth()

Returns the width of the marker pattern in millimeters.

<marker>.setSmoothing(mode)

Specifies whether ARToolKit will smooth the estimated marker position based on its history. Can be either True or False. Default is True.

<marker>.getSmoothing()

Returns whether smoothing is enabled on the marker position.

<marker>.getConfidenceValue()

Get the current confidence value of the marker position. Value ranges from 0 to 1. 0 means the marker pattern was not found during the last update. A value greater than 0 means the marker pattern was found with the given confidence.

<marker>.getVisible()

Returns whether the marker was visible during the last update.

The ARMultiMarker object has the following methods in addition to the standard ARMarker methods:

Method

Description

<multimarker>.getNumMarkers()

Returns the number of markers that make up the multi-marker pattern.

<multimarker>.getNumMarkersFound()

Returns the number of markers found during the last update.

<multimarker>.getMarkerList()

Returns a list of the individual markers belonging to the multi-marker pattern.

The individual markers that make up an ARMultiMarker object are standard extension sensor objects. They contain the following method in addition to the standard sensor methods:

Method

Description

<individualMultiMarker>.getVisible()

Returns whether the individual marker was visible during the last update.

By default the individual multi-marker objects will report their position/rotation in global coordinates. If you want the position/rotation in local coordinates, then you must pass the <ar>.MARKER_LOCAL flag to the sensor get methods.

Example

You can find sample scripts using the ARToolkit plugin in the \examples\artoolkit directory of your Vizard installation folder.