IEEE1394ImageProvider.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 VisionX::Component
19 * @author Jan Issac (jan dot issac at gmx dot net)
20 * @date 2011
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
26
28
29#include "Helpers/helpers.h"
30
31// VisionXCore
34
35// VisionXTools
38
39// ArmarXCore
40#include <SimoxUtility/algorithm/string/string_tools.h>
41
43
44using namespace armarx;
45
46namespace visionx
47{
48 void
50 {
51 using namespace visionx::tools;
52
53 videoDimension = getProperty<ImageDimension>("VideoMode").getValue();
54 colorFormat = getProperty<ColorFormat>("ColorMode").getValue();
55 bayerPatternType = getProperty<BayerPatternType>("BayerPatternType").getValue();
56 isFormat7Mode = getProperty<bool>("Format7Mode").getValue();
57 frameRate = getProperty<float>("FrameRate").getValue();
58 std::string uidStr = getProperty<std::string>("CameraUIDs").getValue();
59
60 uids = simox::alg::split(uidStr, "\t ,");
61
62 setNumberImages(uids.size());
64 setImageSyncMode(eCaptureSynchronization);
65
66 // if (isFormat7Mode)
67 // {
68 // ieee1394Capturer =
69 // new CLinux1394Capture2(
70 // visionx::tools::convert(videoDimension),
71 // frameRate,
72 // 0, 0, -1, -1,
73 // colorFormat.colorMode,
74 // visionx::tools::convert(bayerPatternType));
75 // ieee1394Capturer->SetCameraUids(uids);
76 // }
77 // else
78 // {
79 // ieee1394Capturer =
80 // new CLinux1394Capture2(
81 // visionx::tools::convert(videoDimension),
82 // colorFormat.colorMode,
83 // visionx::tools::convert(bayerPatternType),
84 // visionx::tools::convert(frameRate));
85 // ieee1394Capturer->SetCameraUids(uids);
86 // }
87
88 {
89 std::string leftUID, rightUID;
90 int numCameras = 0;
91
92 if (uids.size() > 0)
93 {
94 leftUID = uids.at(0);
95 numCameras = 1;
96 }
97
98 if (uids.size() > 1)
99 {
100 rightUID = uids.at(1);
101 numCameras = 2;
102 }
103
105 new CLinux1394CaptureThreaded2(visionx::tools::convert(videoDimension),
106 colorFormat.colorMode,
109 numCameras,
110 leftUID.c_str(),
111 rightUID.c_str());
112 //ieee1394Capturer = new CLinux1394CaptureThreaded2(-1, CVideoCaptureInterface::e640x480, CVideoCaptureInterface::eRGB24);
113 //ieee1394Capturer = new CLinux1394CaptureThreaded2(CVideoCaptureInterface::e640x480, CVideoCaptureInterface::eBayerPatternToRGB24, ImageProcessor::eBayerRG, CVideoCaptureInterface::e15fps, 2, leftUID.c_str(), rightUID.c_str());
114 //ieee1394Capturer = new CLinux1394CaptureThreaded2(CVideoCaptureInterface::e640x480, CVideoCaptureInterface::eRGB24, ImageProcessor::eBayerRG, CVideoCaptureInterface::e7_5fps, 2, leftUID.c_str(), rightUID.c_str());
115 }
116 }
117
118 void
120 {
121 if (ppImages != NULL)
122 {
123 for (int i = 0; i < getNumberImages(); i++)
124 {
125 delete ppImages[i];
126 }
127
128 delete[] ppImages;
129
130 ppImages = NULL;
131 }
132 }
133
134 void
136 {
137 ARMARX_INFO << "starting to capture" << flush;
138
139 ppImages = new CByteImage*[2];
140
141 for (int i = 0; i < getNumberImages(); i++)
142 {
144 }
145
146
147 if (!ieee1394Capturer->OpenCamera())
148 {
149 throw visionx::exceptions::user ::StartingCaptureFailedException(
150 "Opening cameras failed!");
151 }
152
153
154 ieee1394Capturer->SetGain((unsigned int)-1);
155 ieee1394Capturer->SetExposure((unsigned int)-1);
156 ieee1394Capturer->SetShutter((unsigned int)-1);
157 ieee1394Capturer->SetWhiteBalance(
158 50,
159 50); // better white balance with 49,36. This 50,50 was the default. All objects trained with 50,50.
160 }
161
162 void
164 {
165
166 ieee1394Capturer->CloseCamera();
167
168 if (ppImages != NULL)
169 {
170 for (int i = 0; i < getNumberImages(); i++)
171 {
172 delete ppImages[i];
173 }
174
175 delete[] ppImages;
176
177 ppImages = NULL;
178 }
179 }
180
181 bool
182 IEEE1394ImageProvider::capture(void** ppImageBuffers)
183 {
184 bool succeeded = false;
185
186 switch (getImageFormat().type)
187 {
188 case visionx::eBayerPattern:
189
190 //succeeded = ieee1394Capturer->CaptureBayerPatternImage(ppImages);
191 //break;
192
193 case visionx::eRgb:
194 case visionx::eGrayScale:
195 succeeded = ieee1394Capturer->CaptureImage(ppImages);
196 break;
197
198 /*
199 * Handle image types which are not supported by
200 * IEEE1394ImageProvider
201 */
202 default:
203 ARMARX_ERROR << "Image type not supported!";
204 return false;
205 }
206
207 if (!succeeded)
208 {
209 ARMARX_ERROR << "Capturing failed!";
210 return false;
211 }
212
213 {
214 ImageFormatInfo imageFormat = getImageFormat();
216
217
218 int imageSize = imageFormat.dimension.width * imageFormat.dimension.height *
219 imageFormat.bytesPerPixel;
220 memcpy(ppImageBuffers[0], ppImages[0]->pixels, imageSize);
221 memcpy(ppImageBuffers[1], ppImages[1]->pixels, imageSize);
222 }
223
224 return true;
225 }
226
227std::string
229{
230 return "IEEE1394ImageProvider";
231}
232
233std::string
238
239
241} // namespace visionx
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
Property< PropertyType > getProperty(const std::string &name)
void setImageSyncMode(ImageSyncMode imageSyncMode)
Sets the image synchronization mode.
armarx::SharedMemoryScopedWriteLockPtr getScopedWriteLock()
Retrieve scoped lock for writing to the memory.
IEEE1394 image provider captures images from one or more cameras and supports the following image tra...
bool isFormat7Mode
Indicate whether using format 7 modes or not.
CByteImage ** ppImages
Captured images.
visionx::BayerPatternType bayerPatternType
Specific bayer pattern type, if ColorMode is BayerPattern.
void onStartCapture(float frameRate) override
CLinux1394CaptureThreaded2 * ieee1394Capturer
IEEE1394 Capture.
visionx::ImageDimension videoDimension
Video dimension data.
std::vector< std::string > uids
Camera UID list.
ColorFormat colorFormat
Camera color mode and resulting image time.
std::string getDefaultName() const override
Retrieve default name of component.
ImageFormatInfo getImageFormat(const Ice::Current &c=Ice::emptyCurrent) override
Returns the entire image format info struct via Ice.
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 setNumberImages(int numberImages)
Sets the number of images on each capture.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< SharedMemoryScopedWriteLock > SharedMemoryScopedWriteLockPtr
const LogSender::manipulator flush
Definition LogSender.h:251
CByteImage * createByteImage(const ImageFormatInfo &imageFormat, const ImageType imageType)
Creates a ByteImage for the destination type specified in the given imageProviderInfo.
CByteImage::ImageType convert(const ImageType visionxImageType)
Converts a VisionX image type into an image type of IVT's ByteImage.
ArmarX headers.