RobotsIO
Loading...
Searching...
No Matches
Utils/YarpImageOfMonoFloat/main.cpp
1#include <RobotsIO/Utils/FileToDepth.h>
2#include <RobotsIO/Utils/YarpImageOfMonoFloat.h>
3#include <RobotsIO/Utils/YarpBufferedPort.hpp>
4
5#include <Eigen/Dense>
6
7#include <opencv2/opencv.hpp>
8#include <opencv2/core/eigen.hpp>
9
10#include <yarp/cv/Cv.h>
11#include <yarp/os/Network.h>
12#include <yarp/sig/Image.h>
13
14#include <chrono>
15#include <thread>
16#include <iostream>
17
18using namespace Eigen;
19using namespace RobotsIO::Utils;
20using namespace yarp::sig;
21using namespace yarp::os;
22using namespace std::chrono_literals;
23
24
25int main(int argc, char** argv)
26{
27 Network yarp;
28 if (!yarp.checkNetwork())
29 {
30 std::cout << "::main. Unable to find YARP." << std::endl;
31
32 return EXIT_FAILURE;
33 }
34 YarpBufferedPort<YarpImageOfMonoFloat> port_out("/test/image:o");
35
36 bool valid_depth;
37 Eigen::MatrixXf depth_eigen;
38 std::tie(valid_depth, depth_eigen) = file_to_depth("./depth.float");
39 if (valid_depth)
40 std::cout << "depth image in" << std::endl;
41
42 cv::Mat depth_image;
43 cv::eigen2cv(depth_eigen, depth_image);
44
45 cv::Mat mask_image = cv::imread("./mask.png", cv::IMREAD_COLOR);
46 if (!mask_image.empty())
47 std::cout << "mask image in " << std::endl;
48 cv::cvtColor(mask_image, mask_image, cv::COLOR_BGR2GRAY);
49
50 while (true)
51 {
52 YarpImageOfMonoFloat images;
53 images.image_mono = yarp::cv::fromCvMat<PixelMono>(mask_image);
54 images.image_float = yarp::cv::fromCvMat<PixelFloat>(depth_image);
55
56 port_out.send_data(images);
57
58 std::this_thread::sleep_for(1s);
59 }
60}