Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpMegaPoseTracker.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Tracker based on MegaPose.
32 */
33
34#include <visp3/core/vpConfig.h>
35
36#if defined(VISP_HAVE_NLOHMANN_JSON) && defined(VISP_HAVE_THREADS)
37
38#include <visp3/dnn_tracker/vpMegaPoseTracker.h>
39#include <future>
40
42std::future<vpMegaPoseEstimate> vpMegaPoseTracker::init(const vpImage<vpRGBa> &I, const vpRect &bb)
43{
44 return std::async(std::launch::async, [&I, &bb, this]() -> vpMegaPoseEstimate {
45 std::vector<vpRect> bbs = { bb };
46 m_poseEstimate = m_megapose->estimatePoses(I, { m_objectLabel }, nullptr, 0.0, &bbs, nullptr)[0];
47 m_initialized = true;
48 return m_poseEstimate;
49 });
50}
51std::future<vpMegaPoseEstimate> vpMegaPoseTracker::init(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cTo)
52{
53 return std::async(std::launch::async, [&I, &cTo, this]() -> vpMegaPoseEstimate {
54 std::vector<vpHomogeneousMatrix> poses = { cTo };
55 m_poseEstimate = m_megapose->estimatePoses(I, { m_objectLabel }, nullptr, 0.0, nullptr, &poses)[0];
56 m_initialized = true;
57 return m_poseEstimate;
58 });
59}
60
61std::future<vpMegaPoseEstimate> vpMegaPoseTracker::track(const vpImage<vpRGBa> &I)
62{
63 if (!m_initialized) {
64 throw vpException(vpException::notInitialized, "MegaPose tracker was not initialized. Call init before calling track.");
65 }
66 return std::async(std::launch::async, [&I, this]() -> vpMegaPoseEstimate {
67 std::vector<vpHomogeneousMatrix> poses = { m_poseEstimate.cTo };
68 m_poseEstimate = m_megapose->estimatePoses(I, { m_objectLabel }, nullptr, 0.0, nullptr, &poses, m_refinerIterations)[0];
69 return m_poseEstimate;
70 });
71}
72
74{
75 m_poseEstimate.cTo = cTo;
76}
77END_VISP_NAMESPACE
78#elif !defined(VISP_BUILD_SHARED_LIBS)
79// Work around to avoid warning: libvisp_dnn_tracker.a(vpMegaPoseTracker.cpp.o) has no symbols
80void dummy_vpMegaPoseTracker() { }
81
82#endif
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ notInitialized
Used to indicate that a parameter is not initialized.
Definition vpException.h:74
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:131
std::future< vpMegaPoseEstimate > track(const vpImage< vpRGBa > &I)
Track the object in the image. Requires the tracker to be initialized by calling init.
std::future< vpMegaPoseEstimate > init(const vpImage< vpRGBa > &I, const vpRect &bb)
Initialize tracking. Performs a full object pose estimation with megapose.
void updatePose(const vpHomogeneousMatrix &cTo)
Update the current pose estimate with a new one, provided by an external source. No operation (such a...
Defines a rectangle in the plane.
Definition vpRect.h:79