Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpMegaPose.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 * MegaPose wrapper.
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/vpMegaPose.h>
39
40#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
41#include <arpa/inet.h>
42#include <netdb.h>
43#include <netinet/in.h>
44#include <sys/socket.h>
45#include <unistd.h>
46#else
47#include <io.h>
48
49#if defined(__clang__)
50// Mute warning : non-portable path to file '<WinSock2.h>'; specified path differs in case from file name on disk [-Wnonportable-system-include-path]
51# pragma clang diagnostic push
52# pragma clang diagnostic ignored "-Wnonportable-system-include-path"
53#endif
54
55#include <winsock2.h>
56
57#if defined(__clang__)
58# pragma clang diagnostic pop
59#endif
60
61#include <ws2tcpip.h> // for inet_pton()
62#endif
63#include <stdexcept>
64#include <mutex>
65#include <thread>
66using json = nlohmann::json;
67
69
71
72/*Encode elements to a buffer of bytes*/
73
74/*End of template recursion*/
75void encode(std::vector<uint8_t> &)
76{
77
78}
79
80/*
81Append the byte representation of an object to the byte buffer.
82By default a generic object cannot be encoded.
83*/
84template<typename T>
85void encode(std::vector<uint8_t> &buffer, const T &object) = delete;
86
87
88/*Single object specializations*/
89template<>
90void encode(std::vector<uint8_t> &buffer, const int &object)
91{
92 const uint32_t v = htonl(object);
93 const uint8_t *varr = (uint8_t *)&v;
94 buffer.insert(buffer.end(), varr, varr + 4);
95}
96
97template<>
98void encode(std::vector<uint8_t> &buffer, const float &object)
99{
100 assert((sizeof(uint32_t) == sizeof(float)));
101 const uint32_t *pointer = reinterpret_cast<const uint32_t *>(&object);
102 const uint32_t v = htonl(*pointer);
103 const uint8_t *varr = (uint8_t *)&v;
104 buffer.insert(buffer.end(), varr, varr + 4);
105}
106
107template<>
108void encode(std::vector<uint8_t> &buffer, const std::string &object)
109{
110 const int size = static_cast<int>(object.size());
111 encode(buffer, size);
112 const uint8_t *chars = (uint8_t *)&object[0];
113 buffer.insert(buffer.end(), chars, chars + size);
114}
115
116template<typename T>
117void encode(std::vector<uint8_t> &buffer, const std::vector<T> &object)
118{
119 const int size = static_cast<int>(object.size());
120 encode(buffer, size);
121 for (const T &value : object) {
122 encode(buffer, value);
123 }
124}
125
126/*Multiple arguments are processed one by one*/
127template<typename T, typename ...Rest>
128void encode(std::vector<uint8_t> &buffer, const T &object, const Rest& ...rest)
129{
130 encode(buffer, object);
131 encode(buffer, rest...);
132}
133
134template<>
135void encode(std::vector<uint8_t> &buffer, const vpImage<vpRGBa> &object)
136{
137 const int height = object.getHeight(), width = object.getWidth();
138 encode(buffer, height, width, 4);
139 const uint32_t sentSize = height * width * 4;
140
141 buffer.reserve(buffer.size() + sentSize); // Avoid resizing multiple times as we iterate on pixels
142 const uint8_t *const bitmap = (uint8_t *)object.bitmap;
143 buffer.insert(buffer.end(), bitmap, bitmap + sentSize);
144 //std::copy(bitmap, bitmap + sentSize, buffer.end());
145}
146
147template<>
148void encode(std::vector<uint8_t> &buffer, const vpImage<uint16_t> &object)
149{
150 const int height = object.getHeight(), width = object.getWidth();
151 encode(buffer, height, width);
152 //test endianness
153 const uint16_t hostTest = 1;
154 const uint16_t netTest = htons(hostTest); // network is big endian
155 const uint8_t endianness = hostTest == netTest ? '>' : '<';
156 const uint32_t sentSize = height * width * 2;
157
158 buffer.reserve(buffer.size() + sentSize + 1);
159 buffer.push_back(endianness);
160 const uint8_t *const bitmap = (uint8_t *)object.bitmap;
161 buffer.insert(buffer.end(), bitmap, bitmap + sentSize);
162}
163
164template<>
165void encode(std::vector<uint8_t> &buffer, const vpCameraParameters &object)
166{
167 encode(buffer, static_cast<float>(object.get_px()), static_cast<float>(object.get_py()),
168 static_cast<float>(object.get_u0()), static_cast<float>(object.get_v0()));
169}
170
171template<>
172void encode(std::vector<uint8_t> &buffer, const vpHomogeneousMatrix &object)
173{
174 std::vector<float> array;
175 array.reserve(16);
176 const double *const data = object.data;
177 for (unsigned i = 0; i < 16; ++i) {
178 array.push_back(static_cast<float>(data[i]));
179 }
180 encode(buffer, array);
181}
182
183/*Decode elements (passed as references), given a buffer of bytes and an index (modified)*/
184
185void decode(const std::vector<uint8_t> &, unsigned int &)
186{ }
187
188/*
189 Modify an object, given a byte array and an index reading into the byte array.
190 The byte array is not modified. But the index should be modified once the object is read.
191 After calling this function, the index should indicate the position of the next object to be read.
192
193 There is no default decoding behaviour. As such, specializations must be written.
194*/
195template<typename T>
196void decode(const std::vector<uint8_t> &buffer, unsigned int &index, T &t) = delete;
197
198template<>
199void decode(const std::vector<uint8_t> &buffer, unsigned int &index, int &value)
200{
201 const uint8_t *ptr = &buffer[index];
202 value = ntohl(*((uint32_t *)ptr)); // Convert from network (big endian) representation to this machine's representation.
203 index += sizeof(int);
204}
205template<>
206void decode(const std::vector<uint8_t> &buffer, unsigned int &index, float &value)
207{
208 const uint8_t *ptr = &buffer[index];
209 const uint32_t v = ntohl(*((uint32_t *)ptr));
210 memcpy(&value, &v, sizeof(uint32_t));
211 index += sizeof(float);
212}
213template<>
214void decode(const std::vector<uint8_t> &buffer, unsigned int &index, std::string &value)
215{
216 int size;
217 decode(buffer, index, size);
218 value.resize(size);
219 value.replace(0, size, (char *)&buffer[index], size);
220 index += size;
221}
222
223template<typename T>
224void decode(const std::vector<uint8_t> &buffer, unsigned int &index, std::vector<T> &value)
225{
226 int size;
227 decode(buffer, index, size);
228 value.resize(size);
229 for (int i = 0; i < size; ++i) {
230 T t;
231 decode(buffer, index, t);
232 value[i] = t;
233 }
234}
235
236template<>
237void decode(const std::vector<uint8_t> &buffer, unsigned int &index, vpHomogeneousMatrix &value)
238{
239 std::vector<float> values;
240 decode(buffer, index, values);
241 assert(values.size() == 16);
242 for (int i = 0; i < 16; ++i) {
243 value.data[i] = values[i];
244 }
245}
246
247/*
248 Decode multiple objects from a byte array.
249 These objects can have different types. They are read from the buffer in the order that they are given to the function.
250*/
251template<typename T, typename ...Rest>
252void decode(const std::vector<uint8_t> &buffer, unsigned int &index, T &object, Rest& ...rest)
253{
254 decode(buffer, index, object);
255 decode(buffer, index, rest...);
256}
257
258template<>
259void decode(const std::vector<uint8_t> &buffer, unsigned int &index, vpImage<vpRGBa> &value)
260{
261 int height, width, channels;
262 decode(buffer, index, height, width, channels);
263 value.resize(height, width);
264 if (channels == 3) {
265 for (int i = 0; i < height; ++i) {
266 for (int j = 0; j < width; ++j) {
267 value.bitmap[i * width + j] = vpRGBa(buffer[index], buffer[index + 1], buffer[index + 2], 255);
268 index += 3;
269 }
270 }
271 }
272 else if (channels == 4) { // Despite having 4 channels, this is faster
273 const unsigned copySize = height * width * channels;
274 memcpy((uint8_t *)value.bitmap, &buffer[index], copySize);
275 index += copySize;
276 }
277}
278
279
280#define MEGAPOSE_CODE_SIZE 4
281void handleWrongReturnMessage(const vpMegaPose::ServerMessage code, std::vector<uint8_t> &buffer)
282{
283 if (code != vpMegaPose::ServerMessage::ERR) {
284 throw vpException(vpException::fatalError, "MegaPose: got an unexpected message from the server: " + std::to_string(code));
285 }
286 std::string message;
287 unsigned index = 0;
288 decode(buffer, index, message);
289 throw vpException(vpException::badValue, "Server error : " + message);
290}
291
292const std::unordered_map<vpMegaPose::ServerMessage, std::string> vpMegaPose::m_codeMap =
293{
294 {ServerMessage::ERR, "RERR"},
295 {ServerMessage::OK, "OKOK"},
296 {ServerMessage::GET_POSE, "GETP"},
297 {ServerMessage::RET_POSE, "RETP"},
298 {ServerMessage::SET_INTR, "INTR"},
299 {ServerMessage::GET_VIZ, "GETV"},
300 {ServerMessage::RET_VIZ, "RETV"},
301 {ServerMessage::GET_SCORE, "GSCO"},
302 {ServerMessage::RET_SCORE, "RSCO"},
303 {ServerMessage::SET_SO3_GRID_SIZE, "SO3G"},
304 {ServerMessage::GET_LIST_OBJECTS, "GLSO"},
305 {ServerMessage::RET_LIST_OBJECTS, "RLSO"},
306 {ServerMessage::EXIT, "EXIT"},
307};
308
309std::string vpMegaPose::messageToString(const vpMegaPose::ServerMessage messageType)
310{
311 return m_codeMap.at(messageType);
312}
313
314vpMegaPose::ServerMessage vpMegaPose::stringToMessage(const std::string &s)
315{
316 for (auto it : m_codeMap) {
317 if (it.second == s) {
318 return it.first;
319 }
320 }
321 return UNKNOWN;
322}
323
324void vpMegaPose::makeMessage(const vpMegaPose::ServerMessage messageType, std::vector<uint8_t> &data) const
325{
326 const uint32_t size = htonl(static_cast<uint32_t>(data.size()));
327 const std::string code = messageToString(messageType);
328 uint8_t arr[sizeof(size) + MEGAPOSE_CODE_SIZE];
329 memcpy(arr, (uint8_t *)&size, sizeof(size));
330
331 memcpy(arr + sizeof(size), (uint8_t *)code.c_str(), MEGAPOSE_CODE_SIZE);
332
333 std::vector<uint8_t> header(arr, arr + sizeof(size) + MEGAPOSE_CODE_SIZE);
334 data.insert(data.begin(), header.begin(), header.end());
335}
336
337std::pair<vpMegaPose::ServerMessage, std::vector<uint8_t>> vpMegaPose::readMessage() const
338{
339 uint32_t size;
340#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
341 size_t readCount = read(m_serverSocket, &size, sizeof(uint32_t));
342#else
343 size_t readCount = recv(m_serverSocket, reinterpret_cast<char *>(&size), sizeof(uint32_t), 0);
344#endif
345 if (readCount != sizeof(uint32_t)) {
346 throw vpException(vpException::ioError, "MegaPose: Error while reading data from socket");
347 }
348 size = ntohl(size);
349
350 unsigned char code[MEGAPOSE_CODE_SIZE];
351#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
352 readCount = read(m_serverSocket, code, MEGAPOSE_CODE_SIZE);
353#else
354 readCount = recv(m_serverSocket, reinterpret_cast<char *>(code), MEGAPOSE_CODE_SIZE, 0);
355#endif
356 if (readCount != MEGAPOSE_CODE_SIZE) {
357 throw vpException(vpException::ioError, "MegaPose: Error while reading data from socket");
358 }
359
360 std::vector<uint8_t> data;
361 data.resize(size);
362 unsigned read_size = 4096;
363 unsigned read_total = 0;
364 while (read_total < size) {
365#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
366 int actually_read = read(m_serverSocket, &data[read_total], read_size);
367#else
368 int actually_read = recv(m_serverSocket, reinterpret_cast<char *>(&data[read_total]), read_size, 0);
369#endif
370 if (actually_read <= 0) {
371 throw vpException(vpException::ioError, "MegaPose: Error while reading data from socket");
372 }
373 read_total += actually_read;
374 }
375 std::string codeStr(code, code + MEGAPOSE_CODE_SIZE);
376 vpMegaPose::ServerMessage c = stringToMessage(codeStr);
377 return std::make_pair(c, data);
378}
379
380vpMegaPose::vpMegaPose(const std::string &host, int port, const vpCameraParameters &cam, unsigned height, unsigned width)
381{
382#if defined(_WIN32)
383 WSADATA WSAData;
384 if (WSAStartup(MAKEWORD(2, 0), &WSAData) != 0) {
385 throw vpException(vpException::ioError, "Could not perform WSAStartup");
386 }
387#endif
388 struct sockaddr_in serv_addr;
389#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
390 if ((m_serverSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
391#else
392 if ((m_serverSocket = static_cast<int>(socket(AF_INET, SOCK_STREAM, 0))) < 0) {
393#endif
394 throw vpException(vpException::ioError, "Could not create socket to connect to MegaPose server");
395 }
396 serv_addr.sin_family = AF_INET;
397 serv_addr.sin_port = htons(port);
398 // Convert string to a binary address representation
399 if (inet_pton(AF_INET, host.c_str(), &serv_addr.sin_addr) <= 0) {
400 throw vpException(vpException::badValue, "Invalid ip address: " + host);
401 }
402 //Initiate connection
403 if ((m_fd = connect(m_serverSocket, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) < 0) {
404 throw vpException(vpException::ioError, "Could not connect to server at " + host + ":" + std::to_string(port));
405 }
406 setIntrinsics(cam, height, width);
407 }
408
410{
411 std::vector<uint8_t> data;
412 makeMessage(ServerMessage::EXIT, data);
413 send(m_serverSocket, reinterpret_cast<const char *>(data.data()), static_cast<int>(data.size()), 0);
414
415#if defined(_WIN32)
416 WSACleanup();
417#else
418 close(m_fd);
419#endif
420}
421
422std::vector<vpMegaPoseEstimate>
423vpMegaPose::estimatePoses(const vpImage<vpRGBa>&image, const std::vector<std::string>&labels,
424 const vpImage<uint16_t>*const depth, const double depth_to_m,
425 const std::vector<vpRect>*const detections, const std::vector<vpHomogeneousMatrix>*const initial_cTos,
426 int refinerIterations)
427{
428 const std::lock_guard<std::mutex> lock(m_mutex);
429 std::vector<uint8_t> data;
430 encode(data, image);
431 json parametersJson;
432 parametersJson["labels"] = labels;
433
434 if (detections == nullptr && initial_cTos == nullptr) {
435 throw vpException(vpException::badValue, "You must either provide detections (bounding boxes) or initial pose estimates for MegaPose to work.");
436 }
437
438 if (detections != nullptr) {
439 if (detections->size() != labels.size()) {
440 throw vpException(vpException::badValue, "Same number of bounding boxes and labels must be provided.");
441 }
442 json detectionsJson = json::array();
443 for (const vpRect &bb : *detections) {
444 json j;
445 to_megapose_json(j, bb);
446 detectionsJson.push_back(j);
447 }
448 parametersJson["detections"] = detectionsJson;
449 }
450
451 if (initial_cTos != nullptr) {
452 if (initial_cTos->size() != labels.size()) {
453 throw vpException(vpException::badValue, "An initial estimate should be given for each detected object in the image");
454 }
455 json cToJson = json::array();
456 for (const vpHomogeneousMatrix &cTo : *initial_cTos) {
457 json j;
458 to_megapose_json(j, cTo);
459 cToJson.push_back(j);
460 }
461 parametersJson["initial_cTos"] = cToJson;
462 }
463 if (refinerIterations >= 0) {
464 parametersJson["refiner_iterations"] = refinerIterations;
465 }
466 if (depth != nullptr) {
467 if (depth_to_m <= 0.0) {
468 throw vpException(vpException::badValue, "When using depth, the scale factor should be specified.");
469 }
470 parametersJson["use_depth"] = true;
471 parametersJson["depth_scale_to_m"] = depth_to_m;
472 }
473 else {
474 parametersJson["use_depth"] = false;
475 }
476 encode(data, parametersJson.dump());
477 if (depth != nullptr) {
478 encode(data, *depth);
479 }
480 makeMessage(ServerMessage::GET_POSE, data);
481 send(m_serverSocket, reinterpret_cast<const char *>(data.data()), static_cast<int>(data.size()), 0);
482 //std::cout<< "Encoding time = " << (vpTime::measureTimeMs() - beforeEncoding) << std::endl;
483
484 ServerMessage code;
485 std::vector<uint8_t> data_result;
486 std::tie(code, data_result) = readMessage();
487
488 unsigned int index = 0;
489 if (code != ServerMessage::RET_POSE) {
490 handleWrongReturnMessage(code, data_result);
491 }
492 std::string jsonStr;
493 decode(data_result, index, jsonStr);
494 json jsonValue = json::parse(jsonStr);
495 std::vector<vpMegaPoseEstimate> result = jsonValue;
496 return result;
497}
498
499std::vector<double> vpMegaPose::scorePoses(const vpImage<vpRGBa>&image,
500 const std::vector<std::string>&labels, const std::vector<vpHomogeneousMatrix>&cTos)
501{
502 const std::lock_guard<std::mutex> lock(m_mutex);
503 std::vector<uint8_t> data;
504 if (cTos.size() != labels.size()) {
505 throw vpException(vpException::generalExceptionEnum::badValue, "The number of poses should be the same as the number of object labels");
506 }
507 encode(data, image);
508 json parametersJson;
509 json cToJson = json::array();
510 for (const vpHomogeneousMatrix &cTo : cTos) {
511 json j;
512 to_megapose_json(j, cTo);
513 cToJson.push_back(j);
514 }
515 parametersJson["cTos"] = cToJson;
516 parametersJson["labels"] = labels;
517
518 encode(data, parametersJson.dump());
519 makeMessage(ServerMessage::GET_SCORE, data);
520 send(m_serverSocket, reinterpret_cast<const char *>(data.data()), static_cast<int>(data.size()), 0);
521
522 ServerMessage code;
523 std::vector<uint8_t> data_result;
524 std::tie(code, data_result) = readMessage();
525
526 if (code != ServerMessage::RET_SCORE) {
527 handleWrongReturnMessage(code, data_result);
528 }
529 unsigned int index = 0;
530 std::string jsonStr;
531 decode(data_result, index, jsonStr);
532 json jsonValue = json::parse(jsonStr);
533 std::vector<double> result = jsonValue;
534 return result;
535}
536
537
538void vpMegaPose::setIntrinsics(const vpCameraParameters& cam, unsigned height, unsigned width)
539{
540 const std::lock_guard<std::mutex> lock(m_mutex);
541 std::vector<uint8_t> data;
542
543 json message;
544 message["px"] = cam.get_px();
545 message["py"] = cam.get_py();
546 message["u0"] = cam.get_u0();
547 message["v0"] = cam.get_v0();
548 message["h"] = height;
549 message["w"] = width;
550
551 encode(data, message.dump());
552 makeMessage(ServerMessage::SET_INTR, data);
553
554 send(m_serverSocket, reinterpret_cast<const char *>(data.data()), static_cast<int>(data.size()), 0);
555 ServerMessage code;
556 std::vector<uint8_t> data_result;
557 std::tie(code, data_result) = readMessage();
558 if (code != ServerMessage::OK) {
559 handleWrongReturnMessage(code, data_result);
560 }
561}
562
563vpImage<vpRGBa> vpMegaPose::viewObjects(const std::vector<std::string>&objectNames,
564 const std::vector<vpHomogeneousMatrix>&poses, const std::string& viewType)
565{
566 const std::lock_guard<std::mutex> lock(m_mutex);
567 std::vector<uint8_t> data;
568 json j;
569 j["labels"] = objectNames;
570 json cToJson = json::array();
571 for (const vpHomogeneousMatrix &cTo : poses) {
572 json j;
573 to_megapose_json(j, cTo);
574 cToJson.push_back(j);
575 }
576 j["poses"] = cToJson;
577 j["type"] = viewType;
578 encode(data, j.dump());
579 makeMessage(ServerMessage::GET_VIZ, data);
580 send(m_serverSocket, reinterpret_cast<const char *>(data.data()), static_cast<int>(data.size()), 0);
581 ServerMessage code;
582 std::vector<uint8_t> data_result;
583 std::tie(code, data_result) = readMessage();
584
585 if (code != ServerMessage::RET_VIZ) {
586 handleWrongReturnMessage(code, data_result);
587 }
588 vpImage<vpRGBa> result;
589 unsigned int index = 0;
590 decode(data_result, index, result);
591 return result;
592}
593
594void vpMegaPose::setCoarseNumSamples(const unsigned num)
595{
596 const std::lock_guard<std::mutex> lock(m_mutex);
597 std::vector<uint8_t> data;
598 json j;
599 j["so3_grid_size"] = num;
600 encode(data, j.dump());
601 makeMessage(ServerMessage::SET_SO3_GRID_SIZE, data);
602 send(m_serverSocket, reinterpret_cast<const char *>(data.data()), static_cast<int>(data.size()), 0);
603 ServerMessage code;
604 std::vector<uint8_t> data_result;
605 std::tie(code, data_result) = readMessage();
606 if (code != ServerMessage::OK) {
607 handleWrongReturnMessage(code, data_result);
608 }
609}
610
611std::vector<std::string> vpMegaPose::getObjectNames()
612{
613 const std::lock_guard<std::mutex> lock(m_mutex);
614 std::vector<uint8_t> data;
615 makeMessage(ServerMessage::GET_LIST_OBJECTS, data);
616 send(m_serverSocket, reinterpret_cast<const char *>(data.data()), static_cast<int>(data.size()), 0);
617 ServerMessage code;
618 std::vector<uint8_t> data_result;
619 std::tie(code, data_result) = readMessage();
621 handleWrongReturnMessage(code, data_result);
622 }
623 unsigned int index = 0;
624 std::string jsonStr;
625 decode(data_result, index, jsonStr);
626 json jsonValue = json::parse(jsonStr);
627 std::vector<std::string> result = jsonValue;
628 return result;
629}
630END_VISP_NAMESPACE
631#else
632
633// Work around to avoid libvisp_dnn_tracker library empty when threads are not used
634class VISP_EXPORT dummy_vpMegaPose
635{
636public:
637 dummy_vpMegaPose() { }
638};
639
640#if !defined(VISP_BUILD_SHARED_LIBS)
641// Work around to avoid warning: libvisp_dnn_tracker.a(vpMegaPose.cpp.o) has no symbols
642void dummy_vpMegaPose_fct() { }
643#endif
644
645#endif
Type * data
Address of the first element of the data array.
Definition vpArray2D.h:149
Generic class defining intrinsic camera parameters.
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ ioError
I/O error.
Definition vpException.h:67
@ badValue
Used to indicate that a value is not in the allowed range.
Definition vpException.h:73
@ fatalError
Fatal error.
Definition vpException.h:72
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:131
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
Definition vpImage.h:544
Type * bitmap
points toward the bitmap
Definition vpImage.h:135
void setIntrinsics(const vpCameraParameters &cam, unsigned height, unsigned width)
vpImage< vpRGBa > viewObjects(const std::vector< std::string > &objectNames, const std::vector< vpHomogeneousMatrix > &poses, const std::string &viewType)
std::vector< vpMegaPoseEstimate > estimatePoses(const vpImage< vpRGBa > &image, const std::vector< std::string > &objectNames, const vpImage< uint16_t > *const depth=nullptr, const double depthToM=0.f, const std::vector< vpRect > *const detections=nullptr, const std::vector< vpHomogeneousMatrix > *const initial_cTos=nullptr, int refinerIterations=-1)
std::vector< std::string > getObjectNames()
Query the server to find the name of all of the objects it knows.
@ GET_LIST_OBJECTS
Ask the server to set the number of samples for coarse estimation.
Definition vpMegaPose.h:168
@ GET_VIZ
Code sent when server returns pose estimates.
Definition vpMegaPose.h:162
@ SET_SO3_GRID_SIZE
Code sent when server returns a pose score.
Definition vpMegaPose.h:167
@ RET_SCORE
Ask the server to score a pose estimate.
Definition vpMegaPose.h:166
@ GET_POSE
Server has successfully completed operation, no return value expected.
Definition vpMegaPose.h:160
@ RET_VIZ
Ask the server for a rendering of the object.
Definition vpMegaPose.h:163
@ OK
An error occurred server side.
Definition vpMegaPose.h:159
@ SET_INTR
Code sent when server returns the rendering of an object.
Definition vpMegaPose.h:164
@ GET_SCORE
Set the intrinsics for the MegaPose server.
Definition vpMegaPose.h:165
@ RET_POSE
Ask the server to estimate poses.
Definition vpMegaPose.h:161
void setCoarseNumSamples(const unsigned num)
std::vector< double > scorePoses(const vpImage< vpRGBa > &image, const std::vector< std::string > &objectNames, const std::vector< vpHomogeneousMatrix > &cTos)
vpMegaPose(const std::string &host, int port, const vpCameraParameters &cam, unsigned height, unsigned width)
Defines a rectangle in the plane.
Definition vpRect.h:79