From 4b92ef0f5de14fa836a0c13721633b1ccb01f95e Mon Sep 17 00:00:00 2001 From: jgvictores Date: Wed, 16 Dec 2020 14:20:18 +0100 Subject: [PATCH] add exampleRemoteGrabber - https://github.com/roboticslab-uc3m/teo-developer-manual/issues/68 --- .travis.yml | 3 + .../cpp/exampleRemoteGrabber/CMakeLists.txt | 17 ++++++ .../exampleRemoteGrabber.cpp | 60 +++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 examples/cpp/exampleRemoteGrabber/CMakeLists.txt create mode 100644 examples/cpp/exampleRemoteGrabber/exampleRemoteGrabber.cpp diff --git a/.travis.yml b/.travis.yml index 65c91565..111b5707 100644 --- a/.travis.yml +++ b/.travis.yml @@ -89,6 +89,9 @@ before_script: - mkdir -p "$TRAVIS_BUILD_DIR/build/exampleProcessCloud" && cd "$_" - cmake "$TRAVIS_BUILD_DIR/examples/cpp/exampleProcessCloud" && make + - mkdir -p "$TRAVIS_BUILD_DIR/build/exampleRemoteGrabber" && cd "$_" + - cmake "$TRAVIS_BUILD_DIR/examples/cpp/exampleRemoteGrabber" && make + - mkdir -p "$TRAVIS_BUILD_DIR/build/exampleRemoteRGBDSensor" && cd "$_" - cmake "$TRAVIS_BUILD_DIR/examples/cpp/exampleRemoteRGBDSensor" && make diff --git a/examples/cpp/exampleRemoteGrabber/CMakeLists.txt b/examples/cpp/exampleRemoteGrabber/CMakeLists.txt new file mode 100644 index 00000000..62671f6a --- /dev/null +++ b/examples/cpp/exampleRemoteGrabber/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.12 FATAL_ERROR) + +project(exampleRemoteGrabber LANGUAGES CXX) + +find_package(YARP 3.2 REQUIRED COMPONENTS os dev sig) + +add_executable(exampleRemoteGrabber exampleRemoteGrabber.cpp) + +target_link_libraries(exampleRemoteGrabber YARP::YARP_os + YARP::YARP_init + YARP::YARP_dev + YARP::YARP_sig) + +include(GNUInstallDirs) + +install(TARGETS exampleRemoteGrabber + DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/examples/cpp/exampleRemoteGrabber/exampleRemoteGrabber.cpp b/examples/cpp/exampleRemoteGrabber/exampleRemoteGrabber.cpp new file mode 100644 index 00000000..7af68c68 --- /dev/null +++ b/examples/cpp/exampleRemoteGrabber/exampleRemoteGrabber.cpp @@ -0,0 +1,60 @@ +// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- + +/** + * @ingroup vision_examples + * @defgroup exampleRemoteGrabber exampleRemoteGrabber + * @brief This example connects to a remote grabber (generally, RGB) device. + */ + +#include + +#include +#include + +#include +#include + +int main(int argc, char *argv[]) +{ + yarp::os::Network yarp; + + if (!yarp::os::Network::checkNetwork()) + { + std::printf("Please start a yarp name server first\n"); + return 1; + } + + yarp::os::Property options; + + options.put("device","remote_grabber"); + options.put("local","/exampleRemoteGrabber"); + options.put("remote","/grabber"); + + yarp::dev::PolyDriver dd(options); + + if (!dd.isValid()) + { + std::printf("Device not available.\n"); + return 1; + } + + yarp::dev::IFrameGrabberImage *iFrameGrabberImage; + + if (!dd.view(iFrameGrabberImage)) + { + std::printf("[error] Problems acquiring interface\n"); + return 1; + } + + std::printf("[success] acquired interface\n"); + + // The following delay should avoid bad status + yarp::os::Time::delay(1); + + std::printf("Width: %d\n", iFrameGrabberImage->width()); + std::printf("Height: %d\n", iFrameGrabberImage->height()); + + dd.close(); + + return 0; +}