StreamImageProvider.cpp
Go to the documentation of this file.
1/**
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package TabletTeleoperation::ArmarXObjects::StreamImageProvider
19 * @author Mirko Waechter ( mirko dot waechter at kit dot edu )
20 * @date 2013
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#include "StreamImageProvider.h"
26
27// VisionX
29
30using namespace armarx;
31
32void
34{
35 this->streamReceiver = receiver;
36}
37
38void
40{
41
42 setNumberImages(streamReceiver->getNumberOfImages());
43
44 int imgWidth = 0;
45 int imgHeight = 0;
46 int imgType = 0;
47
48 streamReceiver->getImageInformation(imgWidth, imgHeight, imgType);
49
50 // ARMARX_WARNING << "image imformation : w: " << imgWidth << " h: " << imgHeight << " t: " << imgType ;
51
52 visionx::ImageType colorType = visionx::ImageType(imgType);
53 CByteImage::ImageType byteType = visionx::tools::convert(colorType);
54
55
56 //ARMARX_WARNING << "expected : x: " << visionx::eRgb << " y: " << CByteImage::eRGB24;
57 //ARMARX_WARNING << "colorType : " << colorType << " byteType " << byteType ;
58
59 setImageFormat(visionx::ImageDimension(imgWidth, imgHeight), colorType);
60 ARMARX_INFO << "Images: " << getNumberImages();
61 for (int i = 0; i < getNumberImages(); ++i)
62 {
63 images.push_back(new CByteImage(imgWidth, imgHeight, byteType));
64 }
65
66
67 ImageProvider::onConnectComponent();
68}
69
70void
72{
73 // set imageprovider properties
74 imagePullTask = new PeriodicTask<StreamImageProvider>(
75 this, &StreamImageProvider::pullImages, 30, true, "PullImages");
76 usingProxy("StreamReceiver");
77}
78
79void
81{
82 imagePullTask->start();
83}
84
85void
87{
88 imagePullTask->stop();
89
90 for (auto& i : images)
91 {
92 delete i;
93 }
94}
95
96void
97StreamImageProvider::pullImages()
98{
99 ARMARX_INFO << deactivateSpam(1) << "Pulling images";
100 streamReceiver->getImages(images);
101 provideImages(&images[0]);
102}
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
The periodic task executes one thread method repeatedly using the time period specified in the constr...
void onConnectImageProvider()
This is called when the Component::onConnectComponent() setup is called.
void setReceiver(StreamReceiverPtr receiver)
void onExitImageProvider()
This is called when the Component::onExitComponent() setup is called.
void onConnectComponent()
Pure virtual hook for the subclass.
void onInitImageProvider()
This is called when the Component::onInitComponent() is called.
void setImageFormat(ImageDimension imageDimension, ImageType imageType, BayerPatternType bayerPatternType=visionx::eBayerPatternRg)
Sets the image basic format data.
int getNumberImages(const Ice::Current &c=Ice::emptyCurrent) override
Retrieve number of images handled by this provider.
void provideImages(void **inputBuffers, const IceUtil::Time &imageTimestamp=IceUtil::Time())
send images raw.
void setNumberImages(int numberImages)
Sets the number of images on each capture.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< StreamReceiver > StreamReceiverPtr
CByteImage::ImageType convert(const ImageType visionxImageType)
Converts a VisionX image type into an image type of IVT's ByteImage.