Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoSource_DcamPMD.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 #ifndef WIN32
25 #include <unistd.h>
26 #else
27 #include <Base/Common/W32Compat.hh>
28 #endif //WIN32
29 
30 #include <string>
31 #include <sstream>
32 #include <iostream>
33 
34 #include "VideoSource_DcamPMD.hh"
35 #include <Base/Image/ImageIO.hh>
36 #include <Image/Camera.hh>
37 
38 #include <Base/Common/BIASpragma.hh>
39 #include <Base/Common/FileHandling.hh>
40 
41 using namespace BIAS;
42 using namespace std;
43 
44 
47 {
48  VideoSource::SetSize(64,48,1);
50  Width_ = 752;
51  Height_ = 480;
52 
53 }
54 
57 {
58 }
59 
62 {
63  if (pmdConnectFireWire(&handle_) != PMD_OK) {
64  BIASERR("Connection of PMD-Camera via FireWire failed!");
65  return -1;
66  }
67  unsigned int width, height;
68  if (pmdGetWidth(handle_, &width) != PMD_OK) {
69  BIASERR("Error in pmdGetWidth!");
70  return -1;
71  }
72  if (pmdGetHeight(handle_, &height) != PMD_OK) {
73  BIASERR("Error in pmdGetWith!");
74  return -1;
75  }
76  if (pmdGetPixelOrigin(handle_, &pixori_) != PMD_OK) {
77  BIASERR("Error in pmdGetPixelOrigin!");
78  return -1;
79  }
80 
81  Width_ = width;
82  Height_ = height;
83  DepthImg_.Init(Width_, Height_, ColorChannels_, ImageBase::ST_float);
84  DepthImg_.SetColorModel(ImageBase::CM_Grey);
85  ModCoeffImg_.Init(Width_, Height_, ColorChannels_, ImageBase::ST_float);
86  ModCoeffImg_.SetColorModel(ImageBase::CM_Grey);
87 
88  return 0;
89 }
90 
93 {
94  if (pmdDisconnect(handle_) != PMD_OK) {
95  BIASERR("Disonnection of PMD-Camera via FireWire failed!");
96  return -1;
97  }
98  return 0;
99 }
100 
103 {
104  return 0;
105 }
106 
107 
110 {
111  return 0;
112 }
113 
115  if (!img.IsEmpty())
116  BIASERR("VideoSource::InitImage() should be called with uninitialized image");
117  img.Init(Width_, Height_, ColorChannels_, ImageBase::ST_unsignedshortint);
119  return 0;
120 }
121 
122 
124  return pmdSetIntegrationTime(handle_, dIntegrationTime);
125 }
126 
128  unsigned int time =0;
129  int ret = pmdGetIntegrationTime(handle_,&time);
130  if(ret >=0)
131  return (int)time;
132  else
133  return ret;
134 }
135 
137  return pmdSetModulationFrequency(handle_, dModulationFrequency);
138 }
139 
140 
142  unsigned int frequency =0;
143  int ret = pmdGetModulationFrequency(handle_,&frequency);
144  if(ret >=0)
145  return (int)frequency;
146  else
147  return ret;
148 }
149 
150 
151 
153 {
154  BIASERR("Setting gain not supported for PMD cam");
155  return 0;
156 }
157 
159 {
160  BIASERR("Setting shutter not supported for PMD cam");
161  return 0;
162 }
163 
165  BIASERR("Getting shutter not supported for PMD cam");
166  return 0.0;
167 }
168 
170  BIASERR("Getting gain not supported for PMD cam");
171  return 0.0;
172 }
173 
175 {
176 
177  int res=0;
178  if ((res=pmdUpdate(handle_)) != PMD_OK) {
179  BIASERR("Error in pmdUpdate! Error: " << res);
180  return -1;
181  };
182 
183  double *data;
184  if ((res=pmdGetIntensities(handle_, (void**)&data)) != PMD_OK) {
185  BIASERR("Error in pmdGetIntensities! Error: " << res);
186  return -1;
187  };
188  ImageUcharFromDouble_(data, image);
189 
190  timeval tv;
191  gettimeofday(&tv, NULL);
192  image.SetTime(tv.tv_sec,tv.tv_usec);
193 
194  if ((res=pmdGetDistances(handle_, (void**)&data)) != PMD_OK) {
195  BIASERR("Error in pmdGetDistances! Error: " << res);
196  return -1;
197  };
198  ImageFloatFromDouble_(data, DepthImg_);
199  DepthImg_.SetUID(image.GetUID());
200 
201  if ((res=pmdGetAmplitudes(handle_, (void**)&data)) != PMD_OK) {
202  BIASERR("Error in pmdGetAmplitudes! Error: " << res);
203  return -1;
204  };
205  ImageFloatFromDouble_(data, ModCoeffImg_);
206  ModCoeffImg_.SetUID(image.GetUID());
207  return 0;
208 }
209 
210 
212 {
213  double* fps=NULL;
214  if (pmdGetInternalFrameRate(handle_, fps) != PMD_OK) {
215  BIASERR("Error in pmdGetInternalFrameRate!");
216  return -1;
217  }
218  return *fps;
219 }
220 
221 
223 {
224  if (dst.IsEmpty()) {
225  dst.Init(Width_, Height_, ColorChannels_, ImageBase::ST_unsignedchar);
226  }
227 
228  double* pus=data;
229  double min = DBL_MAX;
230  double max = DBL_MIN;
231  for (unsigned int i=0; i<dst.GetWidth()*dst.GetHeight(); i++) {
232  if (*pus<min) min = *pus;
233  if (*pus>max) max = *pus;
234  pus++;
235  }
236  pus=data;
237  unsigned char** puc=dst.GetImageDataArray();
238  unsigned char* pucrow;
239  for (unsigned int x=0; x<dst.GetHeight(); x++) {
240  switch (pixori_) {
241  case 1: pucrow=puc[x]; break;
242  case 2: pucrow=puc[x]+dst.GetWidth()-1; break;
243  case 3: pucrow=puc[dst.GetHeight()-x]; break;
244  case 4: pucrow=puc[dst.GetHeight()-x]+dst.GetWidth()-1; break;
245  default: BIASERR("Unknown Pixel Origin"); BIASABORT;
246  }
247  for (unsigned int y=0; y<dst.GetWidth(); y++) {
248  (*pucrow) = (unsigned char)((double)((*pus)-min)/(double)(max-min)*255.0);
249  switch (pixori_) {
250  case 1:
251  case 3: pucrow++; break;
252  case 2:
253  case 4: pucrow--; break;
254  default: BIASERR("Unknown Pixel Origin"); BIASABORT;
255  }
256  pus++;
257  }
258  }
259  }
260 
261 
263 {
264  if (dst.IsEmpty()) {
265  dst.Init(Width_, Height_, ColorChannels_, ImageBase::ST_float);
266  }
267 
268  double* pus=data;
269  float** puc=dst.GetImageDataArray();
270  float* pucrow;
271  for (unsigned int x=0; x<dst.GetHeight(); x++) {
272  switch (pixori_) {
273  case 1: pucrow=puc[x]; break;
274  case 2: pucrow=puc[x]+dst.GetWidth()-1; break;
275  case 3: pucrow=puc[dst.GetHeight()-x]; break;
276  case 4: pucrow=puc[dst.GetHeight()-x]+dst.GetWidth()-1; break;
277  default: BIASERR("Unknown Pixel Origin"); BIASABORT;
278  }
279  for (unsigned int y=0; y<dst.GetWidth(); y++) {
280  (*pucrow) = (float)(*pus);
281  switch (pixori_) {
282  case 1:
283  case 3: pucrow++; break;
284  case 2:
285  case 4: pucrow--; break;
286  default: BIASERR("Unknown Pixel Origin"); BIASABORT;
287  }
288  pus++;
289  }
290  }
291 }
292 
293 
294 
virtual int GrabSingle(Camera< unsigned char > &image)
Returns the 2D image, and reads depth and modulation coefficients.
virtual void SetSize(int w, int h, int bytesperpixel=1)
Set image size and number of bytes per pixel (e.g.
(16bit) unsigned integer image storage type
Definition: ImageBase.hh:114
Defines a common interface to different devices.
virtual int PostGrab()
Stop anything started in PreGrab()
gray values, 1 channel
Definition: ImageBase.hh:130
virtual int SetShutter(float exptime)
Set shutter (exposure time) to exptime in seconds.
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
double GetFPS()
Returns current framerate.
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
float image storage type
Definition: ImageBase.hh:118
unsigned int GetWidth() const
Definition: ImageBase.hh:312
void ImageFloatFromDouble_(double *data, Image< float > &dst)
virtual int SetGain(float g)
Set gain to g with g[dB].
virtual int OpenDevice()
selects the first available device to open (e.g.
const BIAS::UUID & GetUID() const
returns the UUID of the image
Definition: ImageBase.hh:449
int Width_
Image format.
virtual int SetColorModel(BIAS::ImageBase::EColorModel mode)
Select colormodel to use.
virtual float GetShutter()
Get shutter (exposure time) in seconds.
void ImageUcharFromDouble_(double *data, Image< unsigned char > &dst)
unsigned int GetHeight() const
Definition: ImageBase.hh:319
virtual float GetGain()
Get gain in dB.
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
Definition: Image.cpp:421
int SetIntegrationTime(int dIntegrationTime)
void Init(unsigned int width, unsigned int height, unsigned int nChannels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
Initialize image size and channels.
Definition: ImageBase.cpp:229
virtual int PreGrab()
Do last preparations before grabbing (e.g. start ISO transfer)
(8bit) unsigned char image storage type
Definition: ImageBase.hh:112
void SetTime(unsigned long long int sec, unsigned long long int usec)
Set time and ensure correct format (seconds and useconds after &#39;sec&#39;)
Definition: Camera.hh:124
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
virtual int InitImage(ImageBase &img)
int SetModulationFrequency(int dModulationFrequency)
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase
Definition: Image.hh:153