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
27#include "Helpers/helpers.h"
28
29// VisionXCore
32
33// VisionXTools
36
37// ArmarXCore
38#include <SimoxUtility/algorithm/string/string_tools.h>
39
41
42using namespace armarx;
43
44namespace visionx
45{
46 void
48 {
49 using namespace visionx::tools;
50
51 videoDimension = getProperty<ImageDimension>("VideoMode").getValue();
52 colorFormat = getProperty<ColorFormat>("ColorMode").getValue();
53 bayerPatternType = getProperty<BayerPatternType>("BayerPatternType").getValue();
54 isFormat7Mode = getProperty<bool>("Format7Mode").getValue();
55 frameRate = getProperty<float>("FrameRate").getValue();
56 std::string uidStr = getProperty<std::string>("CameraUIDs").getValue();
57
58 uids = simox::alg::split(uidStr, "\t ,");
59
60 setNumberImages(uids.size());
62 setImageSyncMode(eCaptureSynchronization);
63
64 // if (isFormat7Mode)
65 // {
66 // ieee1394Capturer =
67 // new CLinux1394Capture2(
68 // visionx::tools::convert(videoDimension),
69 // frameRate,
70 // 0, 0, -1, -1,
71 // colorFormat.colorMode,
72 // visionx::tools::convert(bayerPatternType));
73 // ieee1394Capturer->SetCameraUids(uids);
74 // }
75 // else
76 // {
77 // ieee1394Capturer =
78 // new CLinux1394Capture2(
79 // visionx::tools::convert(videoDimension),
80 // colorFormat.colorMode,
81 // visionx::tools::convert(bayerPatternType),
82 // visionx::tools::convert(frameRate));
83 // ieee1394Capturer->SetCameraUids(uids);
84 // }
85
86 {
87 std::string leftUID, rightUID;
88 int numCameras = 0;
89
90 if (uids.size() > 0)
91 {
92 leftUID = uids.at(0);
93 numCameras = 1;
94 }
95
96 if (uids.size() > 1)
97 {
98 rightUID = uids.at(1);
99 numCameras = 2;
100 }
101
103 new CLinux1394CaptureThreaded2(visionx::tools::convert(videoDimension),
104 colorFormat.colorMode,
107 numCameras,
108 leftUID.c_str(),
109 rightUID.c_str());
110 //ieee1394Capturer = new CLinux1394CaptureThreaded2(-1, CVideoCaptureInterface::e640x480, CVideoCaptureInterface::eRGB24);
111 //ieee1394Capturer = new CLinux1394CaptureThreaded2(CVideoCaptureInterface::e640x480, CVideoCaptureInterface::eBayerPatternToRGB24, ImageProcessor::eBayerRG, CVideoCaptureInterface::e15fps, 2, leftUID.c_str(), rightUID.c_str());
112 //ieee1394Capturer = new CLinux1394CaptureThreaded2(CVideoCaptureInterface::e640x480, CVideoCaptureInterface::eRGB24, ImageProcessor::eBayerRG, CVideoCaptureInterface::e7_5fps, 2, leftUID.c_str(), rightUID.c_str());
113 }
114 }
115
116 void
118 {
119 if (ppImages != NULL)
120 {
121 for (int i = 0; i < getNumberImages(); i++)
122 {
123 delete ppImages[i];
124 }
125
126 delete[] ppImages;
127
128 ppImages = NULL;
129 }
130 }
131
132 void
134 {
135 ARMARX_INFO << "starting to capture" << flush;
136
137 ppImages = new CByteImage*[2];
138
139 for (int i = 0; i < getNumberImages(); i++)
140 {
142 }
143
144
145 if (!ieee1394Capturer->OpenCamera())
146 {
147 throw visionx::exceptions::user ::StartingCaptureFailedException(
148 "Opening cameras failed!");
149 }
150
151
152 ieee1394Capturer->SetGain((unsigned int)-1);
153 ieee1394Capturer->SetExposure((unsigned int)-1);
154 ieee1394Capturer->SetShutter((unsigned int)-1);
155 ieee1394Capturer->SetWhiteBalance(
156 50,
157 50); // better white balance with 49,36. This 50,50 was the default. All objects trained with 50,50.
158 }
159
160 void
162 {
163
164 ieee1394Capturer->CloseCamera();
165
166 if (ppImages != NULL)
167 {
168 for (int i = 0; i < getNumberImages(); i++)
169 {
170 delete ppImages[i];
171 }
172
173 delete[] ppImages;
174
175 ppImages = NULL;
176 }
177 }
178
179 bool
180 IEEE1394ImageProvider::capture(void** ppImageBuffers)
181 {
182 bool succeeded = false;
183
184 switch (getImageFormat().type)
185 {
186 case visionx::eBayerPattern:
187
188 //succeeded = ieee1394Capturer->CaptureBayerPatternImage(ppImages);
189 //break;
190
191 case visionx::eRgb:
192 case visionx::eGrayScale:
193 succeeded = ieee1394Capturer->CaptureImage(ppImages);
194 break;
195
196 /*
197 * Handle image types which are not supported by
198 * IEEE1394ImageProvider
199 */
200 default:
201 ARMARX_ERROR << "Image type not supported!";
202 return false;
203 }
204
205 if (!succeeded)
206 {
207 ARMARX_ERROR << "Capturing failed!";
208 return false;
209 }
210
211 {
212 ImageFormatInfo imageFormat = getImageFormat();
214
215
216 int imageSize = imageFormat.dimension.width * imageFormat.dimension.height *
217 imageFormat.bytesPerPixel;
218 memcpy(ppImageBuffers[0], ppImages[0]->pixels, imageSize);
219 memcpy(ppImageBuffers[1], ppImages[1]->pixels, imageSize);
220 }
221
222 return true;
223 }
224} // namespace visionx
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.
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.
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.