RobotsIO
Loading...
Searching...
No Matches
FloatMatrixYarpPort.cpp
1/*
2 * Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT)
3 *
4 * This software may be modified and distributed under the terms of the
5 * BSD 3-Clause license. See the accompanying LICENSE file for details.
6 */
7
8#include <RobotsIO/Utils/FloatMatrixYarpPort.h>
9
10#include <opencv2/core/eigen.hpp>
11
12#include <yarp/cv/Cv.h>
13
14using namespace Eigen;
15using namespace RobotsIO::Utils;
16using namespace yarp::cv;
17using namespace yarp::sig;
18
19
20FloatMatrixYarpPort::FloatMatrixYarpPort(const std::string& port_name) :
21 YarpBufferedPort<yarp::sig::ImageOf<yarp::sig::PixelFloat>>(port_name)
22{}
23
24FloatMatrixYarpPort::~FloatMatrixYarpPort()
25{}
26
27
28bool FloatMatrixYarpPort::freeze(const bool blocking)
29{
30 ImageOf<PixelFloat>* image_float_yarp = receive_data(blocking);
31
32 if (image_float_yarp == nullptr)
33 return false;
34
35 cv::Mat image_float_cv = toCvMat(*image_float_yarp);
36
37 cv::cv2eigen(image_float_cv, matrix_);
38
39 return true;
40}
41
42
43MatrixXf FloatMatrixYarpPort::matrix()
44{
45 return matrix_;
46}