YARP
Yet Another Robot Platform
opencv/main.cpp

An example of using OpenCV with YARP.

/*
* Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
* Copyright (C) 2006-2010 RobotCub Consortium
* All rights reserved.
*
* This software may be modified and distributed under the terms of the
* BSD-3-Clause license. See the accompanying LICENSE file for details.
*/
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <yarp/sig/Image.h>
#include <yarp/cv/Cv.h>
int main(int argc, char *argv[]) {
std::cout<<"Show a circle for 3 seconds..."<<std::endl;
std::cout<<"Creating a YARP image of a nice circle"<<std::endl;
yarpImage.resize(300,200);
yarpImage.zero();
yarpImage.width()/2,yarpImage.height()/2,
yarpImage.height()/4);
yarpImage.width()/2,yarpImage.height()/2,
yarpImage.height()/5);
yarp::sig::file::write(yarpImage,"test-1.ppm");
std::cout<<"Saving YARP image to test-1.ppm"<<std::endl;
std::cout<<"Showing OpenCV image"<<std::endl;
cv::Mat cvImage1=yarp::cv::toCvMat(yarpImage);
cv::namedWindow("test",1);
cv::imshow("test",cvImage1);
std::cout<<"Taking image back into YARP..."<<std::endl;
cv::Mat cvImage2=cvImage1.clone();
auto yarpReturnImage=yarp::cv::fromCvMat<yarp::sig::PixelRgb>(cvImage2);
yarp::sig::file::write(yarpReturnImage,"test-2.ppm");
std::cout<<"Saving YARP image to test-2.ppm"<<std::endl;
cv::waitKey(3000);
cv::destroyWindow("test");
std::cout<<"...done"<<std::endl;
return 0;
}
yarp::cv::toCvMat
::cv::Mat toCvMat(yarp::sig::ImageOf< T > &yarpImage)
Convert a yarp::sig::ImageOf to a cv::Mat object.
main
int main(int argc, char *argv[])
Definition: yarpros.cpp:261
ImageDraw.h
Cv.h
yarp::sig::ImageOf< yarp::sig::PixelRgb >
ImageFile.h
Image.h
yarp::sig::PixelRgb
Packed RGB pixel type.
Definition: Image.h:453
yarp::sig::draw::addCircle
void addCircle(ImageOf< T > &dest, const T &pix, int i, int j, int r)
Definition: ImageDraw.h:43
yarp::sig::file::write
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:971