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