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 
30 using namespace armarx;
31 
32 
33 
34 
35 
37 {
38  this->streamReceiver = receiver;
39 }
40 
42 {
43 
44  setNumberImages(streamReceiver->getNumberOfImages());
45 
46  int imgWidth = 0;
47  int imgHeight = 0;
48  int imgType = 0;
49 
50  streamReceiver->getImageInformation(imgWidth, imgHeight, imgType);
51 
52  // ARMARX_WARNING << "image imformation : w: " << imgWidth << " h: " << imgHeight << " t: " << imgType ;
53 
54  visionx::ImageType colorType = visionx::ImageType(imgType);
55  CByteImage::ImageType byteType = visionx::tools::convert(colorType);
56 
57 
58  //ARMARX_WARNING << "expected : x: " << visionx::eRgb << " y: " << CByteImage::eRGB24;
59  //ARMARX_WARNING << "colorType : " << colorType << " byteType " << byteType ;
60 
61  setImageFormat(visionx::ImageDimension(imgWidth, imgHeight), colorType);
62  ARMARX_INFO << "Images: " << getNumberImages();
63  for (int i = 0; i < getNumberImages(); ++i)
64  {
65  images.push_back(new CByteImage(imgWidth, imgHeight, byteType));
66  }
67 
68 
69  ImageProvider::onConnectComponent();
70 }
71 
73 {
74  // set imageprovider properties
75  imagePullTask = new PeriodicTask<StreamImageProvider>(this, &StreamImageProvider::pullImages, 30, true, "PullImages");
76  usingProxy("StreamReceiver");
77 }
78 
80 {
81  imagePullTask->start();
82 }
83 
85 {
86  imagePullTask->stop();
87 
88  for (auto& i : images)
89  {
90  delete i;
91  }
92 
93 }
94 
95 void StreamImageProvider::pullImages()
96 {
97  ARMARX_INFO << deactivateSpam(1) << "Pulling images";
98  streamReceiver->getImages(images);
99  provideImages(&images[0]);
100 
101 }
StreamImageProvider.h
visionx::ImageProvider::getNumberImages
int getNumberImages(const Ice::Current &c=Ice::emptyCurrent) override
Retrieve number of images handled by this provider.
Definition: ImageProvider.cpp:80
visionx::ImageProvider::setImageFormat
void setImageFormat(ImageDimension imageDimension, ImageType imageType, BayerPatternType bayerPatternType=visionx::eBayerPatternRg)
Sets the image basic format data.
Definition: ImageProvider.cpp:275
armarx::StreamImageProvider::onConnectImageProvider
void onConnectImageProvider()
This is called when the Component::onConnectComponent() setup is called.
Definition: StreamImageProvider.cpp:79
IceInternal::Handle< StreamReceiver >
visionx::tools::convert
CByteImage::ImageType convert(const ImageType visionxImageType)
Converts a VisionX image type into an image type of IVT's ByteImage.
Definition: TypeMapping.cpp:95
armarx::StreamImageProvider::onExitImageProvider
void onExitImageProvider()
This is called when the Component::onExitComponent() setup is called.
Definition: StreamImageProvider.cpp:84
armarx::StreamImageProvider::onInitImageProvider
void onInitImageProvider()
This is called when the Component::onInitComponent() is called.
Definition: StreamImageProvider.cpp:72
visionx::ImageProvider::provideImages
void provideImages(void **inputBuffers, const IceUtil::Time &imageTimestamp=IceUtil::Time())
send images raw.
Definition: ImageProvider.cpp:319
visionx::ImageProvider::setNumberImages
void setNumberImages(int numberImages)
Sets the number of images on each capture.
Definition: ImageProvider.cpp:313
armarx::StreamImageProvider::setReceiver
void setReceiver(StreamReceiverPtr receiver)
Definition: StreamImageProvider.cpp:36
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::Logging::deactivateSpam
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
Definition: Logging.cpp:92
TypeMapping.h
armarx::PeriodicTask
Definition: ArmarXManager.h:70
armarx::StreamImageProvider::onConnectComponent
void onConnectComponent()
Pure virtual hook for the subclass.
Definition: StreamImageProvider.cpp:41
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28