Visual Servoing Platform  version 3.6.1 under development (2024-02-13)

#include </home/soft/visp/visp-web-script/visp/modules/tracker/dnn/include/visp3/dnn_tracker/vpMegaPoseTracker.h>

Public Member Functions

 vpMegaPoseTracker (std::shared_ptr< vpMegaPose > megapose, const std::string &objectLabel, const int refinerIterations)
 
std::future< vpMegaPoseEstimateinit (const vpImage< vpRGBa > &I, const vpRect &bb)
 
std::future< vpMegaPoseEstimateinit (const vpImage< vpRGBa > &I, const vpHomogeneousMatrix &cTo)
 
std::future< vpMegaPoseEstimatetrack (const vpImage< vpRGBa > &I)
 
void updatePose (const vpHomogeneousMatrix &cTo)
 

Detailed Description

A simplified interface to track a single object with MegaPose. This tracker works asynchronously: A call to init or track will not stop the current thread. Rather, an std::future object is returned, and its result should be acquired when it is ready.

To instantiate and use the tracker:

#include <visp3/dnn_tracker/vpMegaPoseTracker.h>
int main()
{
cam.initPersProjWithoutDistortion(500.0, 500.0, 320.0, 240.0);
std::shared_ptr<vpMegaPose> megapose;
try {
megapose = std::make_shared<vpMegaPose>("127.0.0.1", 5555, cam, 480, 640);
}
catch (vpException &e) {
throw vpException(vpException::ioError, "Could not connect to MegaPose server.");
}
vpMegaPoseTracker megaposeTracker(megapose, "my_object_name", 1);
//...
vpRect detection;
vpImage<vpRGBa> I(480, 640);
// Perform object detection for init
// detection = ...;
// Acquire Image I
// I = ...;
std::future<vpMegaPoseEstimate> futurePoseEstimate;
futurePoseEstimate = megaposeTracker.init(I, detection);
// Do something else
vpMegaPoseEstimate estimate = futurePoseEstimate.get(); // Block and await result
bool callMegapose = true; // True when we should call megapose
while(true) { // Run continuously, update results when MegaPose returns new results
// I = ...;
if (!callMegapose && futurePosEstimate.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready) {
// process result
callMegapose = true;
}
if (callMegapose) {
futurePoseEstimate = megaposeTracker.track(I);
callMegapose = false;
}
}
}
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
error that can be emitted by ViSP classes.
Definition: vpException.h:59
@ ioError
I/O error.
Definition: vpException.h:79
A simplified interface to track a single object with MegaPose. This tracker works asynchronously: A c...
Defines a rectangle in the plane.
Definition: vpRect.h:76

For a more detailed usage see Tutorial: Tracking with MegaPose.

Examples
servoAfma6MegaposePBVS.cpp, and tutorial-megapose-live-single-object-tracking.cpp.

Definition at line 98 of file vpMegaPoseTracker.h.

Constructor & Destructor Documentation

◆ vpMegaPoseTracker()

vpMegaPoseTracker::vpMegaPoseTracker ( std::shared_ptr< vpMegaPose megapose,
const std::string &  objectLabel,
const int  refinerIterations 
)
inline

Construct a new MegaPose tracker.

Parameters
[in]megapose: A valid connection to the MegaPose server.
[in]objectLabel: The name of the object to track.
[in]refinerIterations: Number of refiner iterations to perform every time init or track is called. Impacts performance.

Definition at line 108 of file vpMegaPoseTracker.h.

Member Function Documentation

◆ init() [1/2]

std::future< vpMegaPoseEstimate > vpMegaPoseTracker::init ( const vpImage< vpRGBa > &  I,
const vpHomogeneousMatrix cTo 
)

Initialize tracking from an initial pose. The initial pose should be in the neighborhood of the true pose. The pose should be expressed in the camera frame. This method will call MegaPose to correct the initial estimate and initialize the tracking.

Parameters
[in]I: The image in which the object is located.
[in]cTo: An initial, coarse, estimate of the object pose.
Returns
A future object that will contain the result of the pose estimation.

Definition at line 52 of file vpMegaPoseTracker.cpp.

◆ init() [2/2]

std::future< vpMegaPoseEstimate > vpMegaPoseTracker::init ( const vpImage< vpRGBa > &  I,
const vpRect bb 
)

Initialize tracking. Performs a full object pose estimation with megapose.

This is slower than tracking.

Requires a bounding box of the object to track.

Parameters
[in]I: The image in which the object is located.
[in]bb: The bounding box of the object.
Returns
A future object that will contain the result of the pose estimation.

Definition at line 43 of file vpMegaPoseTracker.cpp.

◆ track()

std::future< vpMegaPoseEstimate > vpMegaPoseTracker::track ( const vpImage< vpRGBa > &  I)

Track the object in the image. Requires the tracker to be initialized by calling init.

Parameters
[in]I: The image containing the object to track.
Returns
A future object that will contain the result of the pose estimation.

Definition at line 62 of file vpMegaPoseTracker.cpp.

References vpMegaPoseEstimate::cTo, and vpException::notInitialized.

◆ updatePose()

void vpMegaPoseTracker::updatePose ( const vpHomogeneousMatrix cTo)

Update the current pose estimate with a new one, provided by an external source. No operation (such as init or track) should be running.

Parameters
[in]cTo: The new pose estimate.

Definition at line 74 of file vpMegaPoseTracker.cpp.

References vpMegaPoseEstimate::cTo.