Motive API: Quick Start Guide
An overview of the Motive API.
Last updated
Was this helpful?
An overview of the Motive API.
Last updated
Was this helpful?
SDK/API Support Disclaimer
OptiTrack provides developer tools to enable our customers across a broad set of applications to utilize their systems in the ways that best suit them. Our Motive API through the NatNet SDK and Camera SDK is designed to enable experienced software developers to integrate data transfer and/or system operation with their preferred systems and pipelines. Sample projects are provided with each tool, and we strongly recommend users reference or use the samples as reliable starting points.
The following list specifies the range of support OptiTrack provides for the SDK and API tools:
Using the SDK/API tools requires background knowledge of software development. We do not provide support for basic project setup, compiling, and linking when using the SDK/API to create your own applications.
We ensure the SDK tools and their libraries work as intended. We do not provide support for custom developed applications that have been programmed or modified by users using the SDK tools.
Ticketed support will be provided for licensed Motive users using the Motive API and/or the NatNet SDK tools from the included libraries and sample source codes only.
The Camera SDK is a free product. We do not provide free ticketed support for it.
For other questions, please check out the . Very often, similar development issues are reported and solved there.
This guide provides detailed instructions for commonly used functions of the Motive API for developing custom applications. For a full list of functions, refer to the page. For a sample use case of the API functions, please check out the provided project.
In this guide, the following topics will be covered:
Library files and header files
Initialization and shutdown
Capture setup (Calibration)
Configuring camera settings
Updating captured frames
3D marker tracking
Rigid body tracking
Data streaming
When developing a Motive API project, the linker needs to know where to find the required library files. Do this either by specifying its location within the project or by copying these files to the project folder.
MotiveAPI.h
Motive API libraries (.lib and .dll) are in the lib folder within the Motive install directory, located by default at C:\Program Files\OptiTrack\Motive\lib
. This folder contains library files for both 64-bit (MotiveAPI.dll and MotiveAPI.lib) platforms.
When using the API library, all of the required DLL files must be located in the executable directory. If necessary, copy and paste the MotiveAPI.dll file into the folder with the executable file.
Third-party Libraries
Additional third-party libraries are required for Motive API, and most of the DLL files for these libraries can be found in the Motive install directory C:\Program Files\OptiTrack\Motive\
. Copy and paste all of the DLL files from the Motive installation directory into the directory of the Motive API project to use them. Highlighted items in the below image are all required DLL files.
Lastly, copy the C:\Program Files\OptiTrack\Motive\plugins\platforms
folder and its contents into the EXE folder since those libraries will also be used.
Function declarations and classes are contained in the header file MotiveAPI.h, located in the folder C:\Program Files\OptiTrack\Motive\inc\
.
Always include the directive syntax for adding the MotiveAPI.h header file for all programs that are developed against the Motive API.
Motive API, by default, loads the default calibration (MCAL) and Application profile (MOTIVE) files from the program data directory unless otherwise specified. Motive also loads these files at startup. They are located in the following folders:
Default System Calibration: C:\ProgramData\OptiTrack\Motive\System Calibration.mcal
Default Application Profile: C:\ProgramData\OptiTrack\MotiveProfile.motive
Both files can be exported and imported into Motive as needed for the project:
When using the API, connected devices and the Motive API library need to be properly initialized at the beginning of a program and closed down at the end.
The Motive application profile (MOTIVE) stores the following critical information:
All the trackable assets involved in a capture;
Cameras must be calibrated to track in 3D space. Because camera calibration is a complex process, it's easier to calibrate the camera system from Motive, export the camera calibration file (MCAL), then load the exported file into custom applications that are developed against the API.
Loading Calibration
When successfully loaded, you will be able to obtain 3D tracking data using the API functions.
Connected cameras are accessible by index numbers, which are assigned in the order the cameras are initialized. Most API functions for controlling cameras require the camera's index value.
This section covers Motive API functions to check and configure camera frame rate, camera video type, camera exposure, pixel brightness threshold, and IR illumination intensity.
Use the SetCameraProperty function to configure properties outlined below.
At the most fundamental level, these two functions both update the incoming camera frames, but may act differently in certain situations. When a client application stalls momentarily, it can get behind on updating the frames and the unprocessed frames may accumulate. In this situation, these two functions behave differently.
In general, we recommend using the Update function. Only use UpdateSingleFrame in the case when you need to ensure the client application has access to every frame of tracking data and you are not able to call Update in a timely fashion.
Marker Index
In a given frame, each reconstructed marker is assigned a marker index number, which is used to point to a particular reconstruction within a frame. Marker index values may vary between different frames, but unique identifiers always remain the same.
Marker Position
For obtaining 3D position of a reconstructed marker, use the MarkerXYZ function
This section covers functions for tracking Rigid Bodies using the Motive API.
To track the 6 degrees of freedom (DoF) movement of an undeformable object, attach a set of reflective markers to it and use the markers to create a trackable Rigid Body asset.
There are two methods for obtaining Rigid Body assets when using the Motive API:
Import existing Rigid Body data.
Once Rigid Body assets are defined, Rigid Body tracking functions can be used to obtain the 6 DoF tracking data.
Let's go through importing RB assets into a client application using the API. In Motive, Rigid Body assets can be created from three or more reconstructed markers, and all of the created assets can be exported out into either application profile (MOTIVE) Each Rigid Body asset saves marker arrangements when it was first created. As long as the marker locations remain the same, you can use saved asset definitions for tracking respective objects.
Exporting all RB assets from Motive:
Exporting application profile: File → Save Profile
Exporting individual RB asset:
Rigid body assets can be defined directly using the API. The CreateRigidBody function defines a new Rigid Body from given 3D coordinates. This function takes in an array float values which represent x/y/z coordinates or multiple markers in respect to Rigid Body pivot point. The float array for multiple markers should be listed as following: {x1, y1, z1, x2, y2, z2, …, xN, yN, zN}. You can manually enter the coordinate values or use the MarkerXYZ function to input 3D coordinates of tracked markers.
When using the MarkerXYZ function, you need to keep in mind that these locations are taken in respect to the RB pivot point. To set the pivot point at the center of created Rigid Body, you will need to first compute pivot point location, and subtract its coordinates from the 3D coordinates of the markers obtained by the MarkerXYZ function. This process is shown in the following example.
Example: Creating RB Assets
6 DoF Rigid Body tracking data can be obtained using the RigidBodyTransform function. Using this function, you can save 3D position and orientation of a Rigid Body into declared variables. The saved position values indicate location of the Rigid Body pivot point, and they are represented in respect to the global coordinate axis. The Orientation is saved in both Euler and Quaternion orientation representations.
Example: RB Tracking Data
Once the API is successfully initialized, there are two methods of data streaming available.
Once the data streaming is enabled, connect the NatNet client application to the server IP address to start receiving the data.
The Motive API does not support data streaming configuration directly from the API. These properties must be set in Motive.
Export the Motive profile (MOTIVE file) that contains the desired configuration.
Load the exported profile through the API.
Note: You can define this directory by using the MOTIVEAPI_INC
, MOTIVEAPI_LIB
environment variables. Check the project properties (Visual Studio) of the provided project for a sample project configuration.
The can be imported using the function to obtain software settings and trackable asset definitions.
The Calibration file can be imported using the function to ensure reliable 3D tracking data is obtained.
To initialize all of the connected cameras, call the function. This function initializes the API library and gets the cameras ready to capture data, so always call this function at the beginning of a program. If you attempt to use the API functions without initializing first, you will get an error.
loads the default Motive profiles (MOTIVE) from the ProgramData directory during the initialization process. To load a Motive profile from a different directory, use the function.
The function is primarily used for updating captured frames, but it can also be called to update a list of connected devices. Call this function after initialization to make sure all of the newly connected devices are properly initialized in the beginning.
When exiting out of a program, call the function to completely release and close all connected devices. Cameras may fail to shut down completely if this function is not called.
Software configurations including and .
When using the API, we recommend first configuring settings and defining the trackable assets in Motive, then exporting the profile MOTIVE file, to load by calling the function. This allows you to adjust the settings for your needs in advance without having to configure individual settings through the API.
Once the calibration data is loaded, the 3D tracking functions can be used. For detailed instructions on camera calibration in Motive, please read through the page.
In Motive, calibrate the camera system using the Calibration pane. Follow the page for details.
After the system has been calibrated, from Motive.
Using the API, Import the calibration to your custom application by calling the function.
When processing all of the cameras, use the function to obtain the total camera count and process each camera within a loop. To point to a specific camera, use the function to check and use the camera with its given index value.
Camera settings are also located in the Devices pane of Motive. For more information on each of these camera settings, refer to the page.
Corresponds to the setting in Motive's .
Corresponds to the setting in Motive's .
Corresponds to the value in Motive's
Corresponds to the setting in Motive's .
Please see the page for more information on video modes.
Corresponds to the setting in Motive's .
Corresponds to the setting in Motive's .
Corresponds to the setting in Motive's .
Corresponds to the setting in Motive's .
Corresponds to the setting in Motive's .
Corresponds to the setting in Motive's .
Corresponds to the MJPEG Quality setting in Motive's .
Corresponds to the Maximize Power setting in Motive's .
Corresponds to the Bitrate setting in Motive's .
Corresponds to the Bitrate setting in Motive's .
Corresponds to the property in Motive's .
Corresponds to the Logic Version property in Motive's .
There are other camera settings, such as imager gain, that can be configured using the Motive API. Please refer to the page for descriptions on other functions.
To process multiple consecutive frames, call the functions or repeatedly within a loop. In the example below, the Update function is called within a while loop as the frameCounter variable is incremented:
The function disregards accumulated frames and services only the most recent frame data. The client application will not receive the previously missed frames to process.
The function ensures only one frame is processed each time the function is called. If there are significant stalls in the program, using this function may result in accumulated processing latency.
After loading a valid , you can use API functions to track retroreflective markers and get their 3D coordinates. Since marker data is obtained for each frame, always call the or the function each time newly captured frames are received.
You can use the function to obtain the total marker count and use this value within a loop to process all of the reconstructed markers.
Please read the page for detailed instructions on creating and working with Rigid Body assets in Motive.
Define new Rigid Bodies using the function.
Exporting Rigid Body file (profile): Under the , right-click on a RB asset and click Export Rigid Body
When using the API, you can load exported assets by calling the function for application profiles and the or function. When importing profiles, the LoadRigidBodies function will entirely replace the existing Rigid Bodies with the list of assets from the loaded profile. On the other hand, AddRigidBodes will add the loaded assets onto the existing list while keeping the existing assets. Once Rigid Body assets are imported into the application, the API functions can be used to configure and access the Rigid Body assets.
In Motive, Rigid Body assets have assigned to each of them. Depending on how these properties are configured, display and tracking behavior of corresponding Rigid Bodies may vary.
For detailed information on individual Rigid Body settings, read through the page.
The function enables/disables data streaming via the . This client/server networking SDK is designed for sending and receiving OptiTrack data across networks, and can be used to stream tracking data from the API to client applications from various platforms.
The StreamNP function is equivalent to Broadcast Frame Data from the pane in Motive.
Mocap data can be livestreamed through the Virtual Reality Peripheral Network (VRPN) using the function.
Please see the page for information on working with the OptiTrack VRPN sample.
In Motive, configure the streaming server IP address and other data streaming settings. See the page for more information.