3#include <visp3/core/vpConfig.h>
4#include <visp3/core/vpIoTools.h>
5#include <visp3/gui/vpDisplayFactory.h>
6#include <visp3/io/vpImageIo.h>
7#include <visp3/core/vpImageDraw.h>
9int main(
int argc,
char *argv[])
11#if defined(VISP_HAVE_DISPLAY) && defined(VISP_HAVE_MINIZ) && defined(VISP_HAVE_WORKING_REGEX)
12#ifdef ENABLE_VISP_NAMESPACE
16 bool opencv_backend =
false;
17 std::string npz_filename =
"npz_tracking_teabox.npz";
18 bool print_cMo =
false;
19 bool dump_infos =
false;
21 for (
int i = 1;
i < argc;
i++) {
22 if (std::string(argv[i]) ==
"--cv-backend") {
23 opencv_backend =
true;
25 else if ((std::string(argv[i]) ==
"--read" || std::string(argv[i]) ==
"-i") && (i+1 < argc)) {
26 npz_filename = argv[
i+1];
29 else if (std::string(argv[i]) ==
"--print-cMo") {
32 else if (std::string(argv[i]) ==
"--dump") {
36 std::cout <<
"Options:" << std::endl;
37 std::cout <<
" --cv-backend use OpenCV if available for in-memory PNG decoding" << std::endl;
38 std::cout <<
" --read / -i input filename in npz format" << std::endl;
39 std::cout <<
" --print-cMo print cMo" << std::endl;
40 std::cout <<
" --dump print all the data name in the file" << std::endl;
45 std::cout <<
"Read file: " << npz_filename << std::endl;
46 std::cout <<
"OpenCV backend? " << opencv_backend << std::endl;
53 std::cout << npz_filename <<
" file contains the following data:" << std::endl;
54 for (visp::cnpy::npz_t::const_iterator it = npz_data.begin(); it != npz_data.end(); ++it) {
55 std::cout <<
" " << it->first << std::endl;
64 int channel = *arr_channel.
data<
int>();
65 std::cout <<
"height: " <<
height << std::endl;
66 std::cout <<
"width: " <<
width << std::endl;
67 std::cout <<
"channel: " << channel << std::endl;
68 std::cout <<
"Color mode? " << (channel > 1) << std::endl;
74 std::vector<char> vec_arr_camera_name = arr_camera_name.
as_vec<
char>();
75 const std::string
camera_name = std::string(vec_arr_camera_name.begin(), vec_arr_camera_name.end());
76 std::cout <<
"Camera name: " <<
camera_name << std::endl;
83 std::cout <<
"Cam: " <<
cam << std::endl;
88#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
93 display->init(I_display, 100, 100,
"Model-based tracker");
96 int nb_data = *arr_nb_data.
data<
int>();
97 std::cout <<
"Number of images: " << nb_data << std::endl;
101 int *vec_img_data_size_ptr = arr_vec_img_data_size.
data<
int>();
103 unsigned char *vec_img_ptr = arr_vec_img.
data<
unsigned char>();
104 std::vector<unsigned char> vec_img;
105 size_t img_data_offset = 0;
109 double *vec_poses_ptr = arr_vec_poses.
data<
double>();
110 assert(arr_vec_poses.
shape.size() == 2);
111 assert(arr_vec_poses.
shape[1] == 6);
112 size_t pose_size = arr_vec_poses.
shape[1];
114 std::vector<double> times;
116 for (
int iter = 0;
iter < nb_data;
iter++) {
119 vec_img = std::vector<unsigned char>(vec_img_ptr + img_data_offset, vec_img_ptr + img_data_offset + vec_img_data_size_ptr[iter]);
130 times.push_back(end-start);
131 img_data_offset += vec_img_data_size_ptr[
iter];
135 size_t model_sz = *arr_model_iter_sz.
data<
size_t>();
137 for (
size_t i = 0;
i < model_sz;
i++) {
139 int res = snprintf(buffer, 100,
"model_%06d_%06zu", iter, i);
140 if (res > 0 && res < 100) {
141 std::string str_model_iter_data = buffer;
144 if (arr_model_iter_data.
shape[0] >= 5) {
145 if (std::fabs(arr_model_iter_data.
data<
double>()[0]) <= std::numeric_limits<double>::epsilon()) {
155 vpThetaUVector(vec_poses_ptr[pose_size*iter + 3], vec_poses_ptr[pose_size*iter + 4], vec_poses_ptr[pose_size*iter + 5])
159 std::cout <<
"\ncMo:\n" <<
cMo << std::endl;
169 std::cout <<
"Mean time for image decoding: " <<
vpMath::getMean(times) <<
" ms ; Median time: "
173#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
179 std::cerr <<
"Error, a missing display library is needed (X11, GDI or OpenCV built with HighGUI module)." << std::endl;
180#ifndef VISP_HAVE_MINIZ
181 std::cerr <<
"You also need to enable npz I/O functions" << std::endl;
Generic class defining intrinsic camera parameters.
static const vpColor none
Class that defines generic functionalities for display.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0), const std::string &frameName="", const vpColor &textColor=vpColor::black, const vpImagePoint &textOffset=vpImagePoint(15, 15))
static void flush(const vpImage< unsigned char > &I)
Implementation of an homogeneous matrix and operations on such kind of matrices.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void drawLine(vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, unsigned char color, unsigned int thickness=1)
vpImageIoBackendType
Image IO backend for only jpeg and png formats image loading and saving.
@ IO_STB_IMAGE_BACKEND
Use embedded stb_image library.
@ IO_OPENCV_BACKEND
Use OpenCV imgcodecs module.
static void readPNGfromMem(const std::vector< unsigned char > &buffer, vpImage< unsigned char > &I, int backend=IO_DEFAULT_BACKEND)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
static double getMedian(const std::vector< double > &v)
static double getStdev(const std::vector< double > &v, bool useBesselCorrection=false)
static double getMean(const std::vector< double > &v)
Implementation of a rotation vector as axis-angle minimal representation.
Class that consider the case of a translation vector.
VISP_EXPORT npz_t npz_load(const std::string &fname)
std::map< std::string, NpyArray > npz_t
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)
std::vector< size_t > shape
std::vector< T > as_vec() const