Swissranger.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include "../include/cob_camera_sensors/StdAfx.h"
19 #ifdef __LINUX__
22  #include "tinyxml.h"
23 #else
25  #include "cob_common/cob_vision_utils/common/include/cob_vision_utils/VisionUtils.h"
26  #include "cob_vision/windows/src/extern/TinyXml/tinyxml.h"
27 #endif
28 
29 using namespace ipa_CameraSensors;
30 
32 {
34 }
35 
37 {
38  m_initialized = false;
39  m_open = false;
40 
41  m_SRCam = 0;
42  m_DataBuffer = 0;
43  m_BufferSize = 1;
44 
45  m_CoeffsInitialized = false;
46 }
47 
48 
50 {
51  if (isOpen())
52  {
53  Close();
54  }
55 }
56 
57 int ipa_CameraSensors::LibMesaCallback(SRCAM srCam, unsigned int msg, unsigned int param, void* data)
58 {
59  switch(msg)
60  {
61  case CM_MSG_DISPLAY: // Redirects all output to console
62  {
63  if (param==MC_ETH)
64  {
65  // Do nothing
66  return 0;
67  }
68  else
69  {
70  return SR_GetDefaultCallback()(0,msg,param,data);
71  }
72  break;
73  }
74  default:
75  {
76  // Default handling
77  return SR_GetDefaultCallback()(0,msg,param,data);
78  }
79  }
80  return 0;
81 }
82 
83 
84 unsigned long Swissranger::Init(std::string directory, int cameraIndex)
85 {
86  if (isInitialized())
87  {
89  }
90 
92 
93  // Load SR parameters from xml-file
94  if (LoadParameters((directory + "cameraSensorsIni.xml").c_str(), cameraIndex) & RET_FAILED)
95  {
96  std::cerr << "ERROR - Swissranger::Init:" << std::endl;
97  std::cerr << "\t ... Parsing xml configuration file failed." << std::endl;
98  return (RET_FAILED | RET_INIT_CAMERA_FAILED);
99  }
100 
101  m_CoeffsInitialized = true;
102 
103  // Set callback function, to catch annoying ethernet messages
104  SR_SetCallback(LibMesaCallback);
105 
107  {
108  // Load z-calibration files
109  std::string filename = directory + "MatlabCalibrationData/PMD/ZCoeffsA0.xml";
110  CvMat* c_mat = (CvMat*)cvLoad(filename.c_str());
111  if (! c_mat)
112  {
113  std::cerr << "ERROR - PMDCamCube::LoadParameters:" << std::endl;
114  std::cerr << "\t ... Error while loading " << directory + "MatlabCalibrationData/ZcoeffsA0.txt" << "." << std::endl;
115  std::cerr << "\t ... Data is necessary for z-calibration of swissranger camera" << std::endl;
116  m_CoeffsInitialized = false;
117  // no RET_FAILED, as we might want to calibrate the camera to create these files
118  }
119  else
120  {
121  m_CoeffsA0 = c_mat;
122  cvReleaseMat(&c_mat);
123  }
124 
125  filename = directory + "MatlabCalibrationData/PMD/ZCoeffsA1.xml";
126  c_mat = (CvMat*)cvLoad(filename.c_str());
127  if (! c_mat)
128  {
129  std::cerr << "ERROR - PMDCamCube::LoadParameters:" << std::endl;
130  std::cerr << "\t ... Error while loading " << directory + "MatlabCalibrationData/ZcoeffsA1.txt" << "." << std::endl;
131  std::cerr << "\t ... Data is necessary for z-calibration of swissranger camera" << std::endl;
132  m_CoeffsInitialized = false;
133  // no RET_FAILED, as we might want to calibrate the camera to create these files
134  }
135  else
136  {
137  m_CoeffsA1 = c_mat;
138  cvReleaseMat(&c_mat);
139  }
140 
141  filename = directory + "MatlabCalibrationData/PMD/ZCoeffsA2.xml";
142  c_mat = (CvMat*)cvLoad(filename.c_str());
143  if (! c_mat)
144  {
145  std::cerr << "ERROR - PMDCamCube::LoadParameters:" << std::endl;
146  std::cerr << "\t ... Error while loading " << directory + "MatlabCalibrationData/ZcoeffsA2.txt" << "." << std::endl;
147  std::cerr << "\t ... Data is necessary for z-calibration of swissranger camera" << std::endl;
148  m_CoeffsInitialized = false;
149  // no RET_FAILED, as we might want to calibrate the camera to create these files
150  }
151  else
152  {
153  m_CoeffsA2 = c_mat;
154  cvReleaseMat(&c_mat);
155  }
156 
157  filename = directory + "MatlabCalibrationData/PMD/ZCoeffsA3.xml";
158  c_mat = (CvMat*)cvLoad(filename.c_str());
159  if (! c_mat)
160  {
161  std::cerr << "ERROR - PMDCamCube::LoadParameters:" << std::endl;
162  std::cerr << "\t ... Error while loading " << directory + "MatlabCalibrationData/ZcoeffsA3.txt" << "." << std::endl;
163  std::cerr << "\t ... Data is necessary for z-calibration of swissranger camera" << std::endl;
164  m_CoeffsInitialized = false;
165  // no RET_FAILED, as we might want to calibrate the camera to create these files
166  }
167  else
168  {
169  m_CoeffsA3 = c_mat;
170  cvReleaseMat(&c_mat);
171  }
172 
173  filename = directory + "MatlabCalibrationData/PMD/ZCoeffsA4.xml";
174  c_mat = (CvMat*)cvLoad(filename.c_str());
175  if (! c_mat)
176  {
177  std::cerr << "ERROR - PMDCamCube::LoadParameters:" << std::endl;
178  std::cerr << "\t ... Error while loading " << directory + "MatlabCalibrationData/ZcoeffsA4.txt" << "." << std::endl;
179  std::cerr << "\t ... Data is necessary for z-calibration of swissranger camera" << std::endl;
180  m_CoeffsInitialized = false;
181  // no RET_FAILED, as we might want to calibrate the camera to create these files
182  }
183  else
184  {
185  m_CoeffsA4 = c_mat;
186  cvReleaseMat(&c_mat);
187  }
188 
189  filename = directory + "MatlabCalibrationData/PMD/ZCoeffsA5.xml";
190  c_mat = (CvMat*)cvLoad(filename.c_str());
191  if (! c_mat)
192  {
193  std::cerr << "ERROR - PMDCamCube::LoadParameters:" << std::endl;
194  std::cerr << "\t ... Error while loading " << directory + "MatlabCalibrationData/ZcoeffsA5.txt" << "." << std::endl;
195  std::cerr << "\t ... Data is necessary for z-calibration of swissranger camera" << std::endl;
196  m_CoeffsInitialized = false;
197  // no RET_FAILED, as we might want to calibrate the camera to create these files
198  }
199  else
200  {
201  m_CoeffsA5 = c_mat;
202  cvReleaseMat(&c_mat);
203  }
204 
205  filename = directory + "MatlabCalibrationData/PMD/ZCoeffsA6.xml";
206  c_mat = (CvMat*)cvLoad(filename.c_str());
207  if (! c_mat)
208  {
209  std::cerr << "ERROR - PMDCamCube::LoadParameters:" << std::endl;
210  std::cerr << "\t ... Error while loading " << directory + "MatlabCalibrationData/ZcoeffsA6.txt" << "." << std::endl;
211  std::cerr << "\t ... Data is necessary for z-calibration of swissranger camera" << std::endl;
212  m_CoeffsInitialized = false;
213  // no RET_FAILED, as we might want to calibrate the camera to create these files
214  }
215  else
216  {
217  m_CoeffsA6 = c_mat;
218  cvReleaseMat(&c_mat);
219  }
220  }
221 
222  // set init flag
223  m_initialized = true;
224  m_GrayImageAcquireCalled = false;
225 
226  return RET_OK;
227 }
228 
229 
230 unsigned long Swissranger::Open()
231 {
232  if (!isInitialized())
233  {
235  }
236 
237  if (isOpen())
238  {
239  return (RET_OK | RET_CAMERA_ALREADY_OPEN);
240  }
241 
242  std::string sInterface = "";
243  m_RangeCameraParameters.m_Interface.clear(); // Clear flags
244  m_RangeCameraParameters.m_Interface.seekg(0); // Set Pointer to position 0 within stringstream
245  m_RangeCameraParameters.m_Interface >> sInterface;
246 
247  if (sInterface == "USB")
248  {
249  if(SR_OpenUSB(&m_SRCam, 0)<=0)
250  {
251  std::cerr << "ERROR - Swissranger::Open():" << std::endl;
252  std::cerr << "\t ... Could not open swissranger camera on USB port" << std::endl;
253  std::cerr << "\t ... Unplug and Replugin camera power cable.\n";
254  return RET_FAILED;
255  }
256  }
257  else if (sInterface == "ETHERNET")
258  {
259  std::string sIP = "";
260  m_RangeCameraParameters.m_IP.clear(); // Clear flags
261  m_RangeCameraParameters.m_IP.seekg(0); // Set Pointer to position 0 within stringstream
263  if(SR_OpenETH(&m_SRCam, sIP.c_str())<=0)
264  {
265  std::cerr << "ERROR - Swissranger::Open():" << std::endl;
266  std::cerr << "\t ... Could not open swissranger camera on ETHERNET port" << std::endl;
267  std::cerr << "\t ... with ip '" << sIP << "'." << std::endl;
268  std::cerr << "\t ... Unplug and Replugin camera power cable to fix problem\n";
269  return RET_FAILED;
270  }
271  }
272  else
273  {
274  std::cerr << "ERROR - Swissranger::Open():" << std::endl;
275  std::cerr << "\t ... Unknown interface type '" << sInterface << "'" << std::endl;
276  return RET_FAILED;
277  }
278 
279  //char DevStr[1024];
280  //SR_GetDeviceString(m_SRCam, DevStr, 1024);
281  //std::cout << "Swissranger::Open(): INFO" << std::endl;
282  //std::cout << "\t ... " << DevStr << std::endl;
283 
285  {
286  std::cerr << "ERROR - AVTPikeCam::Open:" << std::endl;
287  std::cerr << "\t ... Could not set parameters" << std::endl;
288  return RET_FAILED;
289  }
290 
291  std::cout << "**************************************************" << std::endl;
292  std::cout << "Swissranger::Open: Swissranger camera device OPEN" << std::endl;
293  std::cout << "**************************************************" << std::endl << std::endl;
294  m_open = true;
295 
296  return RET_OK;
297 }
298 
299 
300 unsigned long Swissranger::Close()
301 {
302  if (!isOpen())
303  {
304  return (RET_OK);
305  }
306 
307  if(SR_Close(m_SRCam)<0)
308  {
309  std::cout << "ERROR - Swissranger::Close():" << std::endl;
310  std::cerr << "\t ... Could not close swissranger camera." << std::endl;
311  return RET_FAILED;
312  }
313  m_SRCam = 0;
314 
315  m_open = false;
316  return RET_OK;
317 
318 }
319 
320 
321 unsigned long Swissranger::SetProperty(t_cameraProperty* cameraProperty)
322 {
323  if (!m_SRCam)
324  {
325  return (RET_FAILED | RET_CAMERA_NOT_OPEN);
326  }
327 
328  int err = 0;
329  switch (cameraProperty->propertyID)
330  {
332  if (cameraProperty->propertyType & ipa_CameraSensors::TYPE_SPECIAL)
333  {
334  if(cameraProperty->specialValue == ipa_CameraSensors::VALUE_AUTO)
335  {
336  unsigned short val = 0;
337  err =SR_SetAmplitudeThreshold(m_SRCam, val);
338  if(err<0)
339  {
340  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
341  std::cerr << "\t ... Could not set amplitude threshold to AUTO mode" << std::endl;
342  return RET_FAILED;
343  }
344  }
345  else if(cameraProperty->specialValue == ipa_CameraSensors::VALUE_DEFAULT)
346  {
347  // Void
348  }
349  else
350  {
351  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
352  std::cerr << "\t ... Special value 'VALUE_AUTO' or 'VALUE_DEFAULT' expected." << std::endl;
353  return RET_FAILED;
354  }
355  }
357  {
358  err =SR_SetAmplitudeThreshold(m_SRCam, cameraProperty->u_shortData);
359  if(err<0)
360  {
361  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
362  std::cerr << "\t ... Could not set amplitude threshold to AUTO mode" << std::endl;
363  return RET_FAILED;
364  }
365  }
366  else
367  {
368  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
369  std::cerr << "\t ... Wrong property type. '(TYPE_SHORT|TYPE_UNSIGNED)' or special value 'TYPE_SPECIAL' expected." << std::endl;
370  return RET_FAILED;
371  }
372  break;
374  if (cameraProperty->propertyType & ipa_CameraSensors::TYPE_SPECIAL)
375  {
376  if(cameraProperty->specialValue == ipa_CameraSensors::VALUE_AUTO)
377  {
378  err = SR_SetAutoExposure(m_SRCam, 1, 150, 5, 40);
379  if(err<0)
380  {
381  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
382  std::cerr << "\t ... Could not set integration time to AUTO mode" << std::endl;
383  return RET_FAILED;
384  }
385  }
386  else if(cameraProperty->specialValue == ipa_CameraSensors::VALUE_DEFAULT)
387  {
388  // Void
389  }
390  else
391  {
392  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
393  std::cerr << "\t ... Special value 'VALUE_AUTO' or 'VALUE_DEFAULT' expected." << std::endl;
394  return RET_FAILED;
395  }
396  }
398  {
399  err = SR_SetAutoExposure(m_SRCam, 0xff, 150, 5, 70);
400  if(err<0)
401  {
402  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
403  std::cerr << "\t ... Could not turn off auto exposure" << std::endl;
404  return RET_FAILED;
405  }
406  err = SR_SetIntegrationTime(m_SRCam, cameraProperty->u_charData);
407  if(err<0)
408  {
409  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
410  std::cerr << "\t ... Could not set amplitude threshold to '" << cameraProperty->u_charData << "'" << std::endl;
411  return RET_FAILED;
412  }
413  }
414  else
415  {
416  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
417  std::cerr << "\t ... Wrong property type. '(TYPE_LONG|TYPE_UNSIGNED)' or special value 'TYPE_SPECIAL' expected." << std::endl;
418  return RET_FAILED;
419  }
420  break;
422  if (cameraProperty->propertyType & ipa_CameraSensors::TYPE_SPECIAL)
423  {
424  if(cameraProperty->specialValue == ipa_CameraSensors::VALUE_AUTO)
425  {
426  err = SR_SetModulationFrequency(m_SRCam, MF_LAST);
427  if(err<0)
428  {
429  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
430  std::cerr << "\t ... Could not set modulation frequency to AUTO mode" << std::endl;
431  return RET_FAILED;
432  }
433  }
434  else if(cameraProperty->specialValue == ipa_CameraSensors::VALUE_DEFAULT)
435  {
436  // Void
437  }
438  else
439  {
440  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
441  std::cerr << "\t ... Special value 'VALUE_AUTO' or 'VALUE_DEFAULT' expected." << std::endl;
442  return RET_FAILED;
443  }
444  }
445  else if (cameraProperty->propertyType & (ipa_CameraSensors::TYPE_STRING))
446  {
447  // MF_40MHz, SR3k: maximal range 3.75m
448  // MF_30MHz, SR3k, SR4k: maximal range 5m
449  // MF_21MHz, SR3k: maximal range 7.14m
450  // MF_20MHz, SR3k: maximal range 7.5m
451  // MF_19MHz, SR3k: maximal range 7.89m
452  // MF_60MHz, SR4k: maximal range 2.5m
453  // MF_15MHz, SR4k: maximal range 10m
454  // MF_10MHz, SR4k: maximal range 15m
455  // MF_29MHz, SR4k: maximal range 5.17m
456  // MF_31MHz
457  if (cameraProperty->stringData == "MF_40MHz")
458  {
459  err = SR_SetModulationFrequency(m_SRCam, MF_40MHz);
460  }
461  else if (cameraProperty->stringData == "MF_30MHz")
462  {
463  err = SR_SetModulationFrequency(m_SRCam, MF_30MHz);
464  }
465  else if (cameraProperty->stringData == "MF_21MHz")
466  {
467  err = SR_SetModulationFrequency(m_SRCam, MF_21MHz);
468  }
469  else if (cameraProperty->stringData == "MF_20MHz")
470  {
471  err = SR_SetModulationFrequency(m_SRCam, MF_20MHz);
472  }
473  else if (cameraProperty->stringData == "MF_19MHz")
474  {
475  err = SR_SetModulationFrequency(m_SRCam, MF_19MHz);
476  }
477  else if (cameraProperty->stringData == "MF_60MHz")
478  {
479  err = SR_SetModulationFrequency(m_SRCam, MF_60MHz);
480  }
481  else if (cameraProperty->stringData == "MF_15MHz")
482  {
483  err = SR_SetModulationFrequency(m_SRCam, MF_15MHz);
484  }
485  else if (cameraProperty->stringData == "MF_10MHz")
486  {
487  err = SR_SetModulationFrequency(m_SRCam, MF_10MHz);
488  }
489  else if (cameraProperty->stringData == "MF_29MHz")
490  {
491  err = SR_SetModulationFrequency(m_SRCam, MF_29MHz);
492  }
493  else if (cameraProperty->stringData == "MF_31MHz")
494  {
495  err = SR_SetModulationFrequency(m_SRCam, MF_31MHz);
496  }
497  else
498  {
499  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
500  std::cerr << "\t ... Modulation frequency " << cameraProperty->stringData << " unknown" << std::endl;
501  }
502 
503  if(err<0)
504  {
505  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
506  std::cerr << "\t ... Could not set modulation frequency " << cameraProperty->stringData << std::endl;
507  return RET_FAILED;
508  }
509 
510  }
511  else
512  {
513  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
514  std::cerr << "\t ... Wrong property type. '(TYPE_LONG|TYPE_UNSIGNED)' or special value 'TYPE_SPECIAL' expected." << std::endl;
515  return RET_FAILED;
516  }
517  break;
518  case PROP_ACQUIRE_MODE:
519  if (cameraProperty->propertyType & ipa_CameraSensors::TYPE_INTEGER)
520  {
521  err = SR_SetMode(m_SRCam, cameraProperty->integerData);
522  if(err<0)
523  {
524  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
525  std::cerr << "\t ... Could not set acquire mode" << std::endl;
526  return RET_FAILED;
527  }
528  }
529  else
530  {
531  std::cerr << "ERROR - Swissranger::SetProperty:" << std::endl;
532  std::cerr << "\t ... Wrong property type. 'TYPE_INTEGER' expected." << std::endl;
533  return RET_FAILED;
534  }
535  break;
536  default:
537  std::cout << "Swissranger::SetProperty: Property " << cameraProperty->propertyID << " unspecified.\n";
538  return RET_FAILED;
539  break;
540  }
541 
542  return RET_OK;
543 }
544 
545 
547 {
549 }
550 
551 
552 unsigned long Swissranger::GetProperty(t_cameraProperty* cameraProperty)
553 {
554  switch (cameraProperty->propertyID)
555  {
557  cameraProperty->u_integerData = m_BufferSize;
558  return RET_OK;
559  break;
561  if (isOpen())
562  {
563  cameraProperty->u_shortData = SR_GetAmplitudeThreshold(m_SRCam);
564  cameraProperty->propertyType = (TYPE_UNSIGNED | TYPE_SHORT);
565  }
566  else
567  {
568  return (RET_FAILED | RET_CAMERA_NOT_OPEN);
569  }
570  break;
571 
573  if (isOpen())
574  {
575  cameraProperty->u_charData = SR_GetIntegrationTime(m_SRCam);
576  cameraProperty->propertyType = (TYPE_UNSIGNED | TYPE_CHARACTER);
577  }
578  else
579  {
580  return (RET_FAILED | RET_CAMERA_NOT_OPEN);
581  }
582  break;
583 
584  case PROP_ACQUIRE_MODE:
585  if (isOpen())
586  {
587  cameraProperty->integerData = SR_GetMode(m_SRCam);
588  cameraProperty->propertyType = TYPE_INTEGER;
589  }
590  else
591  {
592  return (RET_FAILED | RET_CAMERA_NOT_OPEN);
593  }
594  break;
595 
597  if (isOpen())
598  {
599  cameraProperty->cameraResolution.xResolution = (int)SR_GetCols(m_SRCam);
600  cameraProperty->cameraResolution.yResolution = (int)SR_GetRows(m_SRCam);
601  cameraProperty->propertyType = TYPE_CAMERA_RESOLUTION;
602  }
603  else
604  {
605  cameraProperty->cameraResolution.xResolution = 176;
606  cameraProperty->cameraResolution.yResolution = 144;
607  cameraProperty->propertyType = TYPE_CAMERA_RESOLUTION;
608  }
609  break;
610 
611  default:
612  std::cout << "ERROR - Swissranger::GetProperty:" << std::endl;
613  std::cout << "\t ... Property " << cameraProperty->propertyID << " unspecified.";
614  return RET_FAILED;
615  break;
616 
617  }
618 
619  return RET_OK;
620 }
621 
622 
623 // Wrapper for IplImage retrival from AcquireImage
624 // Images have to be initialized prior to calling this function
625 unsigned long Swissranger::AcquireImages(cv::Mat* rangeImage, cv::Mat* grayImage, cv::Mat* cartesianImage,
626  bool getLatestFrame, bool undistort, ipa_CameraSensors::t_ToFGrayImageType grayImageType)
627 {
628  char* rangeImageData = 0;
629  char* grayImageData = 0;
630  char* cartesianImageData = 0;
631  int widthStepRange = -1;
632  int widthStepGray = -1;
633  int widthStepCartesian = -1;
634 
635  int width = -1;
636  int height = -1;
638  cameraProperty.propertyID = PROP_CAMERA_RESOLUTION;
639  GetProperty(&cameraProperty);
640  width = cameraProperty.cameraResolution.xResolution;
641  height = cameraProperty.cameraResolution.yResolution;
642 
643  if(rangeImage)
644  {
645  rangeImage->create(height, width, CV_32FC(1));
646  rangeImageData = rangeImage->ptr<char>(0);
647  widthStepRange = rangeImage->step;
648  }
649 
650  if(grayImage)
651  {
652  grayImage->create(height, width, CV_32FC(1));
653  grayImageData = grayImage->ptr<char>(0);
654  widthStepGray = grayImage->step;
655  }
656 
657  if(cartesianImage)
658  {
659  cartesianImage->create(height, width, CV_32FC(3));
660  cartesianImageData = cartesianImage->ptr<char>(0);
661  widthStepCartesian = cartesianImage->step;
662  }
663 
664  if (!rangeImage && !grayImage && !cartesianImage)
665  {
666  return RET_OK;
667  }
668 
669  return AcquireImages(widthStepRange, widthStepGray, widthStepCartesian, rangeImageData, grayImageData, cartesianImageData, getLatestFrame, undistort, grayImageType);
670 
671 }
672 
673 // Enables faster image retrival than AcquireImage
674 unsigned long Swissranger::AcquireImages(int widthStepRange, int widthStepGray, int widthStepCartesian, char* rangeImageData, char* grayImageData, char* cartesianImageData,
675  bool getLatestFrame, bool undistort, ipa_CameraSensors::t_ToFGrayImageType grayImageType)
676 {
678 // Get data from camera
680  if (!m_open)
681  {
682  std::cerr << "ERROR - Swissranger::AcquireImages:" << std::endl;
683  std::cerr << "t ... Camera not open." << std::endl;
684  return (RET_FAILED | RET_CAMERA_NOT_OPEN);
685  }
686 
687  //unsigned int c = SR_GetIntegrationTime(m_SRCam);
688  //unsigned short a = SR_GetAmplitudeThreshold(m_SRCam);
689  //std::cout << "\t ... Integration time is '" << c << "'" << std::endl;
690  //std::cout << "\t ... Amplitude threshold is '" << a << "'" << std::endl;
691 
692  int width = -1;
693  int height = -1;
695  cameraProperty.propertyID = PROP_CAMERA_RESOLUTION;
696  GetProperty(&cameraProperty);
697  width = cameraProperty.cameraResolution.xResolution;
698  height = cameraProperty.cameraResolution.yResolution;
699 
700  unsigned int bytesRead = 0;
701  bytesRead = SR_Acquire(m_SRCam);
702  if(bytesRead <= 0)
703  {
704  std::cerr << "ERROR - Swissranger::AcquireImages:" << std::endl;
705  std::cerr << "\t ... Could not acquire image!" << std::endl;
706  return RET_FAILED;
707  }
708 
709  if (getLatestFrame == true)
710  {
711  bytesRead = SR_Acquire(m_SRCam);
712  if(bytesRead <= 0)
713  {
714  std::cerr << "ERROR - Swissranger::AcquireImages:" << std::endl;
715  std::cerr << "\t ... Could not acquire image!" << std::endl;
716  return RET_FAILED;
717  }
718  }
719  WORD* pixels =(WORD*) SR_GetImage(m_SRCam, 0);
721 // Range image (distorted or undistorted)
723  if (rangeImageData)
724  {
725  int imageStep = -1;
726  float* f_ptr = 0;
727 
728  // put data in corresponding IPLImage structures
729  for(unsigned int row=0; row<(unsigned int)height; row++)
730  {
731  imageStep = row*width;
732  f_ptr = (float*)(rangeImageData + row*widthStepRange);
733 
734  for (unsigned int col=0; col<(unsigned int)width; col++)
735  {
736  f_ptr[col] = (float)(pixels[imageStep + col]);
737  }
738  }
739 
740  if (undistort)
741  {
742  cv::Mat undistortedData(height, width, CV_32FC(1), (float*) rangeImageData);
743  cv::Mat distortedData;
744 
745  assert (!m_undistortMapX.empty() && !m_undistortMapY.empty());
746  cv::remap(distortedData, undistortedData, m_undistortMapX, m_undistortMapY, cv::INTER_LINEAR);
747  }
748 
749  } // End if (rangeImage)
750 
752 // Intensity/Amplitude image
753 // ATTENTION: SR provides only amplitude information
755  if(grayImageData)
756  {
757  if (grayImageType == ipa_CameraSensors::INTENSITY_32F1 &&
758  m_GrayImageAcquireCalled == false)
759  {
760  std::cout << "WARNING - Swissranger::AcquireImages:" << std::endl;
761  std::cout << "\t ... Intensity image for swissranger not available" << std::endl;
762  std::cout << "\t ... falling back to amplitude image" << std::endl;
764  }
765 
766  int imageSize = width*height;
767  int imageStep = 0;
768  float* f_ptr = 0;
769 
770  for(unsigned int row=0; row<(unsigned int)height-1; row++)
771  {
772  imageStep = imageSize+row*width;
773  f_ptr = (float*)(grayImageData + row*widthStepGray);
774 
775  for (unsigned int col=0; col<(unsigned int)width-1; col++)
776  {
777  f_ptr[col] = (float)(pixels[imageStep+col]);
778  }
779  }
780 
781  if (undistort)
782  {
783  cv::Mat undistortedData( height, width, CV_32FC1, (float*) grayImageData);
784  cv::Mat distortedData;
785 
786  assert (!m_undistortMapX.empty() && !m_undistortMapY.empty());
787  cv::remap(distortedData, undistortedData, m_undistortMapX, m_undistortMapY, cv::INTER_LINEAR);
788  }
789 
790  }
791 
793 // Cartesian image (always undistorted)
795  if(cartesianImageData)
796  {
797  float x = -1;
798  float y = -1;
799  float zRaw = -1;
800  float* zCalibratedPtr = 0;
801  float zCalibrated = -1;
802  float* f_ptr = 0;
803 
805  {
807  {
808  // Calculate calibrated z values (in meter) based on 6 degree polynomial approximation
809  cv::Mat distortedData( height, width, CV_32FC1 );
810  for(unsigned int row=0; row<(unsigned int)height; row++)
811  {
812  f_ptr = distortedData.ptr<float>(row);
813  for (unsigned int col=0; col<(unsigned int)width; col++)
814  {
815  zRaw = (float)(pixels[width*row + col]);
816  GetCalibratedZMatlab(col, row, zRaw, zCalibrated);
817  f_ptr[col] = zCalibrated;
818  }
819  }
820  /*IplImage dummy;
821  IplImage *z = cvGetImage(distortedData, &dummy);
822  IplImage *image = cvCreateImage(cvGetSize(z), IPL_DEPTH_8U, 3);
823  ipa_Utils::ConvertToShowImage(z, image, 1);
824  cvNamedWindow("Z");
825  cvShowImage("Z", image);
826  cvWaitKey();
827  */
828 
829  // Undistort
830  cv::Mat undistortedData;
831  assert (!m_undistortMapX.empty() && !m_undistortMapY.empty());
832  cv::remap(distortedData, undistortedData, m_undistortMapX, m_undistortMapY, cv::INTER_LINEAR);
833 
834  /*IplImage dummy;
835  IplImage* z = cvGetImage(undistortedData, &dummy);
836  IplImage* image = cvCreateImage(cvGetSize(z), IPL_DEPTH_8U, 3);
837  ipa_utils::ConvertToShowImage(z, image, 1);
838  cvNamedWindow("Z");
839  cvShowImage("Z", image);
840  cvWaitKey();*/
841 
842  // Calculate X and Y based on instrinsic rotation and translation
843  for(unsigned int row=0; row<(unsigned int)height; row++)
844  {
845  zCalibratedPtr = undistortedData.ptr<float>(row);
846  f_ptr = (float*)(cartesianImageData + row*widthStepCartesian);
847 
848  for (unsigned int col=0; col<(unsigned int)width; col++)
849  {
850  int colTimes3 = 3*col;
851  GetCalibratedXYMatlab(col, row, zCalibratedPtr[col], x, y);
852 
853  f_ptr[colTimes3] = x;
854  f_ptr[colTimes3 + 1] = y;
855  f_ptr[colTimes3 + 2] = zCalibratedPtr[col];
856  }
857  }
858  }
859  else
860  {
861  std::cerr << "ERROR - Swissranger::AcquireImages: \n";
862  std::cerr << "\t ... At least one of m_CoeffsA0 ... m_CoeffsA6 not initialized.\n";
863  return RET_FAILED;
864  }
865 
866  }
868  {
869  SR_CoordTrfFlt(m_SRCam, m_X, m_Y, m_Z, sizeof(float), sizeof(float), sizeof(float));
870  // Calculate calibrated z values (in meter) based on 6 degree polynomial approximation
871  cv::Mat distortedData( height, width, CV_32FC1 );
872  for(unsigned int row=0; row<(unsigned int)height; row++)
873  {
874  f_ptr = distortedData.ptr<float>(row);
875  for (unsigned int col=0; col<(unsigned int)width; col++)
876  {
877  GetCalibratedZSwissranger(col, row, width, zCalibrated);
878  f_ptr[col] = zCalibrated;
879  }
880  }
881 
882  // Undistort
883  cv::Mat undistortedData;
884  assert (!m_undistortMapX.empty() && !m_undistortMapY.empty());
885  cv::remap(distortedData, undistortedData, m_undistortMapX, m_undistortMapY, cv::INTER_LINEAR);
886 
887  // Calculate X and Y based on instrinsic rotation and translation
888  for(unsigned int row=0; row<(unsigned int)height; row++)
889  {
890  zCalibratedPtr = undistortedData.ptr<float>(row);
891  f_ptr = (float*)(cartesianImageData + row*widthStepCartesian);
892 
893  for (unsigned int col=0; col<(unsigned int)width; col++)
894  {
895  int colTimes3 = 3*col;
896  GetCalibratedXYMatlab(col, row, zCalibratedPtr[col], x, y);
897 
898  f_ptr[colTimes3] = x;
899  f_ptr[colTimes3 + 1] = y;
900  f_ptr[colTimes3 + 2] = zCalibratedPtr[col];
901  }
902  }
903  }
904  else if(m_CalibrationMethod==NATIVE)
905  {
906  SR_CoordTrfFlt(m_SRCam, m_X, m_Y, m_Z, sizeof(float), sizeof(float), sizeof(float));
907 
908  for(unsigned int row=0; row<(unsigned int)height; row++)
909  {
910  f_ptr = (float*)(cartesianImageData + row*widthStepCartesian);
911 
912  for (unsigned int col=0; col<(unsigned int)width; col++)
913  {
914  int colTimes3 = 3*col;
915 
916  GetCalibratedZSwissranger(col, row, width, zCalibrated);
917  GetCalibratedXYSwissranger(col, row, width, x, y);
918 
919  f_ptr[colTimes3] = x;
920  f_ptr[colTimes3 + 1] = y;
921  f_ptr[colTimes3 + 2] = zCalibrated;
922  }
923  }
924  }
925  else
926  {
927  std::cerr << "ERROR - Swissranger::AcquireImages:" << std::endl;
928  std::cerr << "\t ... Calibration method unknown.\n";
929  return RET_FAILED;
930  }
931  }
932  return RET_OK;
933 }
934 
935 unsigned long Swissranger::SaveParameters(const char* filename)
936 {
938 }
939 
940 unsigned long Swissranger::GetCalibratedZMatlab(int u, int v, float zRaw, float& zCalibrated)
941 {
942 
943  double c[7] = {m_CoeffsA0.at<double>(v,u), m_CoeffsA1.at<double>(v,u), m_CoeffsA2.at<double>(v,u),
944  m_CoeffsA3.at<double>(v,u), m_CoeffsA4.at<double>(v,u), m_CoeffsA5.at<double>(v,u), m_CoeffsA6.at<double>(v,u)};
945  double y = 0;
946  ipa_Utils::EvaluatePolynomial((double) zRaw, 6, &c[0], &y);
947  zCalibrated = (float) y;
948 
949  return RET_OK;
950 }
951 
952 // Return value is in m
953 unsigned long Swissranger::GetCalibratedZSwissranger(int u, int v, int width, float& zCalibrated)
954 {
955  zCalibrated = (float) m_Z[v*width + u];
956 
957  return RET_OK;
958 }
959 
960 // u and v are assumed to be distorted coordinates
961 unsigned long Swissranger::GetCalibratedXYMatlab(int u, int v, float z, float& x, float& y)
962 {
963  // Conversion form m to mm
964  z *= 1000;
965 
966  // Use intrinsic camera parameters
967  double fx, fy, cx, cy;
968 
969  fx = m_intrinsicMatrix.at<double>(0, 0);
970  fy = m_intrinsicMatrix.at<double>(1, 1);
971 
972  cx = m_intrinsicMatrix.at<double>(0, 2);
973  cy = m_intrinsicMatrix.at<double>(1, 2);
974 
975  // Fundamental equation: u = (fx*x)/z + cx
976  if (fx == 0)
977  {
978  std::cerr << "ERROR - Swissranger::GetCalibratedXYZ:" << std::endl;
979  std::cerr << "\t ... fx is 0.\n";
980  return RET_FAILED;
981  }
982  x = (float) (z*(u-cx)/fx) ;
983 
984  // Fundamental equation: v = (fy*y)/z + cy
985  if (fy == 0)
986  {
987  std::cerr << "ERROR - Swissranger::GetCalibratedXYZ:" << std::endl;
988  std::cerr << "\t ... fy is 0.\n";
989  return RET_FAILED;
990  }
991  y = (float) (z*(v-cy)/fy);
992 
993  // Conversion from mm to m
994  x /= 1000;
995  y /= 1000;
996 
997  return RET_OK;
998 }
999 
1000 unsigned long Swissranger::GetCalibratedXYSwissranger(int u, int v, int width, float& x, float& y)
1001 {
1002  // make sure, that m_X, m_Y and m_Z have been initialized by Acquire image
1003  int i = v*width + u;
1004  x = (float)m_X[i];
1005  y = (float)m_Y[i];
1006 
1007  return RET_OK;
1008 }
1009 
1011 {
1012  ipa_CameraSensors::t_cameraProperty cameraProperty;
1013 
1014 
1015 // -----------------------------------------------------------------
1016 // Set amplitude threshold
1017 // -----------------------------------------------------------------
1019  std::string sAmplitudeThreshold = "";
1020  m_RangeCameraParameters.m_AmplitudeThreshold.clear(); // Clear flags
1021  m_RangeCameraParameters.m_AmplitudeThreshold.seekg(0); // Set Pointer to position 0 within stringstream
1022  m_RangeCameraParameters.m_AmplitudeThreshold >> sAmplitudeThreshold;
1023  if (sAmplitudeThreshold == "AUTO")
1024  {
1026  cameraProperty.specialValue = VALUE_AUTO;
1027  }
1028  else if (sAmplitudeThreshold == "DEFAULT")
1029  {
1031  cameraProperty.specialValue = VALUE_DEFAULT;
1032  }
1033  else
1034  {
1036  m_RangeCameraParameters.m_AmplitudeThreshold.clear(); // Clear flags
1037  m_RangeCameraParameters.m_AmplitudeThreshold.seekg(0); // Set Pointer to position 0 within stringstream
1039  }
1040 
1041  if (SetProperty(&cameraProperty) & ipa_CameraSensors::RET_FAILED)
1042  {
1043  std::cout << "WARNING - Swissranger::SetParameters:" << std::endl;
1044  std::cout << "\t ... Could not set amplitude threshold" << std::endl;
1045  }
1046 
1047 // -----------------------------------------------------------------
1048 // Set integration time
1049 // -----------------------------------------------------------------
1051  std::string sIntegrationTime = "";
1052  m_RangeCameraParameters.m_IntegrationTime.clear(); // Clear flags
1053  m_RangeCameraParameters.m_IntegrationTime.seekg(0); // Set Pointer to position 0 within stringstream
1054  m_RangeCameraParameters.m_IntegrationTime >> sIntegrationTime;
1055  if (sIntegrationTime == "AUTO")
1056  {
1058  cameraProperty.specialValue = VALUE_AUTO;
1059  }
1060  else if (sIntegrationTime == "DEFAULT")
1061  {
1063  cameraProperty.specialValue = VALUE_DEFAULT;
1064  }
1065  else
1066  {
1067  std::string tempValue;
1069  m_RangeCameraParameters.m_IntegrationTime.clear(); // Clear flags
1070  m_RangeCameraParameters.m_IntegrationTime.seekg(0); // Set Pointer to position 0 within stringstream
1072  cameraProperty.u_charData = (unsigned char)atoi(tempValue.c_str());
1073  }
1074 
1075  if (SetProperty(&cameraProperty) & ipa_CameraSensors::RET_FAILED)
1076  {
1077  std::cout << "WARNING - Swissranger::SetParameters:" << std::endl;
1078  std::cout << "\t ... Could not set integration time" << std::endl;
1079  }
1080 
1081 // -----------------------------------------------------------------
1082 // Set modulation frequency
1083 // -----------------------------------------------------------------
1085  std::string sModulationFrequency = "";
1086  m_RangeCameraParameters.m_ModulationFrequency.clear(); // Clear flags
1087  m_RangeCameraParameters.m_ModulationFrequency.seekg(0); // Set Pointer to position 0 within stringstream
1088  m_RangeCameraParameters.m_ModulationFrequency >> sModulationFrequency;
1089  if (sModulationFrequency == "AUTO")
1090  {
1092  cameraProperty.specialValue = VALUE_AUTO;
1093  }
1094  else if (sModulationFrequency == "DEFAULT")
1095  {
1097  cameraProperty.specialValue = VALUE_DEFAULT;
1098  }
1099  else
1100  {
1101  cameraProperty.propertyType = (ipa_CameraSensors::TYPE_STRING);
1102  m_RangeCameraParameters.m_ModulationFrequency.clear(); // Clear flags
1103  m_RangeCameraParameters.m_ModulationFrequency.seekg(0); // Set Pointer to position 0 within stringstream
1105  }
1106 
1107  if (SetProperty(&cameraProperty) & ipa_CameraSensors::RET_FAILED)
1108  {
1109  std::cout << "WARNING - Swissranger::SetParameters:" << std::endl;
1110  std::cout << "\t ... Could not set modulation frequency" << std::endl;
1111  }
1112 
1113 // -----------------------------------------------------------------
1114 // Set acquire mode
1115 // -----------------------------------------------------------------
1118  m_RangeCameraParameters.m_AcquireMode.clear(); // Set Pointer to position 0 within stringstream
1119  m_RangeCameraParameters.m_AcquireMode.seekg(0); // Set Pointer to position 0 within stringstream
1121  if (SetProperty(&cameraProperty) & ipa_CameraSensors::RET_FAILED)
1122  {
1123  std::cout << "WARNING - Swissranger::SetParameters:" << std::endl;
1124  std::cout << "\t ... Could not set acquire mode" << std::endl;
1125  }
1126 
1127  return RET_OK;
1128 }
1129 
1130 unsigned long Swissranger::LoadParameters(const char* filename, int cameraIndex)
1131 {
1132  // Load SwissRanger parameters.
1133  boost::shared_ptr<TiXmlDocument> p_configXmlDocument (new TiXmlDocument( filename ));
1134 
1135  if (!p_configXmlDocument->LoadFile())
1136  {
1137  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1138  std::cerr << "\t ... Error while loading xml configuration file \n";
1139  std::cerr << "\t ... (Check filename and syntax of the file):\n";
1140  std::cerr << "\t ... '" << filename << "'" << std::endl;
1141  return (RET_FAILED | RET_FAILED_OPEN_FILE);
1142  }
1143  std::cout << "INFO - Swissranger::LoadParameters:" << std::endl;
1144  std::cout << "\t ... Parsing xml configuration file:" << std::endl;
1145  std::cout << "\t ... '" << filename << "'" << std::endl;
1146 
1147  std::string tempString;
1148  if ( p_configXmlDocument )
1149  {
1150 
1151 //************************************************************************************
1152 // BEGIN LibCameraSensors
1153 //************************************************************************************
1154  // Tag element "LibCameraSensors" of Xml Inifile
1155  TiXmlElement *p_xmlElement_Root = NULL;
1156  p_xmlElement_Root = p_configXmlDocument->FirstChildElement( "LibCameraSensors" );
1157 
1158  if ( p_xmlElement_Root )
1159  {
1160 
1161 //************************************************************************************
1162 // BEGIN LibCameraSensors->Swissranger
1163 //************************************************************************************
1164  // Tag element "Swissranger3000" of Xml Inifile
1165  TiXmlElement *p_xmlElement_Root_SR31 = NULL;
1166  std::stringstream ss;
1167  ss << "Swissranger_" << cameraIndex;
1168  p_xmlElement_Root_SR31 = p_xmlElement_Root->FirstChildElement( ss.str() );
1169  if ( p_xmlElement_Root_SR31 )
1170  {
1171 
1172 //************************************************************************************
1173 // BEGIN LibCameraSensors->Swissranger->Role
1174 //************************************************************************************
1175  // Subtag element "Role" of Xml Inifile
1176  TiXmlElement* p_xmlElement_Child = NULL;
1177  p_xmlElement_Child = p_xmlElement_Root_SR31->FirstChildElement( "Role" );
1178  if ( p_xmlElement_Child )
1179  {
1180  // read and save value of attribute
1181  if ( p_xmlElement_Child->QueryValueAttribute( "value", &tempString ) != TIXML_SUCCESS)
1182  {
1183  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1184  std::cerr << "\t ... Can't find attribute 'value' of tag 'Role'." << std::endl;
1186  }
1187 
1188  if (tempString == "MASTER") m_RangeCameraParameters.m_CameraRole = MASTER;
1189  else if (tempString == "SLAVE") m_RangeCameraParameters.m_CameraRole = SLAVE;
1190  else
1191  {
1192  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1193  std::cerr << "\t ... Role " << tempString << " unspecified." << std::endl;
1194  return (RET_FAILED);
1195  }
1196 
1197  }
1198  else
1199  {
1200  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1201  std::cerr << "\t ... Can't find tag 'Role'." << std::endl;
1202  return (RET_FAILED | RET_XML_TAG_NOT_FOUND);
1203  }
1204 
1205 //************************************************************************************
1206 // BEGIN LibCameraSensors->Swissranger->Interface
1207 //************************************************************************************
1208  // Subtag element "OperationMode" of Xml Inifile
1209  p_xmlElement_Child = NULL;
1210  p_xmlElement_Child = p_xmlElement_Root_SR31->FirstChildElement( "Interface" );
1211  std::string tempString;
1212  if ( p_xmlElement_Child )
1213  {
1214  // read and save value of attribute
1215  if ( p_xmlElement_Child->QueryValueAttribute( "value", &tempString ) != TIXML_SUCCESS)
1216  {
1217  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1218  std::cerr << "\t ... Can't find attribute 'value' of tag 'Interface'." << std::endl;
1220  }
1221  if (tempString == "USB")
1222  {
1223  m_RangeCameraParameters.m_Interface.str( " " ); // Clear stringstream
1224  m_RangeCameraParameters.m_Interface.clear(); // Reset flags
1225  m_RangeCameraParameters.m_Interface << tempString;
1226  }
1227  else if (tempString == "ETHERNET")
1228  {
1229  m_RangeCameraParameters.m_Interface.str( " " ); // Clear stringstream
1230  m_RangeCameraParameters.m_Interface.clear(); // Reset flags
1231  m_RangeCameraParameters.m_Interface << tempString;
1232  // read and save value of attribute
1233  if ( p_xmlElement_Child->QueryValueAttribute( "ip", &tempString ) != TIXML_SUCCESS)
1234  {
1235  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1236  std::cerr << "\t ... Can't find attribute 'ip' of tag 'Interface'." << std::endl;
1238  }
1239  m_RangeCameraParameters.m_IP.str( " " ); // Clear stringstream
1240  m_RangeCameraParameters.m_IP.clear(); // Reset flags
1241  m_RangeCameraParameters.m_IP << tempString;
1242  }
1243  else
1244  {
1245  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1246  std::cerr << "\t ... Interface " << tempString << " unspecified." << std::endl;
1247  return (RET_FAILED);
1248  }
1249  }
1250  else
1251  {
1252  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1253  std::cerr << "\t ... Can't find tag 'Interface'." << std::endl;
1254  return (RET_FAILED | RET_XML_TAG_NOT_FOUND);
1255  }
1256 
1257 //************************************************************************************
1258 // BEGIN LibCameraSensors->Swissranger->AmplitudeThreshold
1259 //************************************************************************************
1260  // Subtag element "IntegrationTime" of Xml Inifile
1261  p_xmlElement_Child = NULL;
1262  p_xmlElement_Child = p_xmlElement_Root_SR31->FirstChildElement( "AmplitudeThreshold" );
1263  if ( p_xmlElement_Child )
1264  {
1265  // read and save value of attribute
1266  if ( p_xmlElement_Child->QueryValueAttribute( "value", &tempString) != TIXML_SUCCESS)
1267  {
1268  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1269  std::cerr << "\t ... Can't find attribute 'value' of tag 'AmplitudeThreshold'." << std::endl;
1271  }
1272  else
1273  {
1274  m_RangeCameraParameters.m_AmplitudeThreshold.str( " " ); // Clear stringstream
1275  m_RangeCameraParameters.m_AmplitudeThreshold.clear(); // Reset flags
1277  }
1278  }
1279  else
1280  {
1281  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1282  std::cerr << "\t ... Can't find tag 'AmplitudeThreshold'." << std::endl;
1283  return (RET_FAILED | RET_XML_TAG_NOT_FOUND);
1284  }
1285 
1286 //************************************************************************************
1287 // BEGIN LibCameraSensors->Swissranger->IntegrationTime
1288 //************************************************************************************
1289  // Subtag element "IntegrationTime" of Xml Inifile
1290  p_xmlElement_Child = NULL;
1291  p_xmlElement_Child = p_xmlElement_Root_SR31->FirstChildElement( "IntegrationTime" );
1292  if ( p_xmlElement_Child )
1293  {
1294  // read and save value of attribute
1295  if ( p_xmlElement_Child->QueryValueAttribute( "value", &tempString) != TIXML_SUCCESS)
1296  {
1297  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1298  std::cerr << "\t ... Can't find attribute 'value' of tag 'IntegrationTime'." << std::endl;
1300  }
1301  else
1302  {
1303  m_RangeCameraParameters.m_IntegrationTime.str( " " ); // Clear stringstream
1304  m_RangeCameraParameters.m_IntegrationTime.clear(); // Reset flags
1306  }
1307  }
1308  else
1309  {
1310  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1311  std::cerr << "\t ... Can't find tag 'IntegrationTime'." << std::endl;
1312  return (RET_FAILED | RET_XML_TAG_NOT_FOUND);
1313  }
1314 
1315 //************************************************************************************
1316 // BEGIN LibCameraSensors->Swissranger->Modulation
1317 //************************************************************************************
1318  // Subtag element "IntegrationTime" of Xml Inifile
1319  p_xmlElement_Child = NULL;
1320  p_xmlElement_Child = p_xmlElement_Root_SR31->FirstChildElement( "Modulation" );
1321  if ( p_xmlElement_Child )
1322  {
1323  // read and save value of attribute
1324  if ( p_xmlElement_Child->QueryValueAttribute( "frequency", &tempString) != TIXML_SUCCESS)
1325  {
1326  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1327  std::cerr << "\t ... Can't find attribute 'frequency' of tag 'Modulation'." << std::endl;
1329  }
1330  else
1331  {
1332  m_RangeCameraParameters.m_ModulationFrequency.str( " " ); // Clear stringstream
1333  m_RangeCameraParameters.m_ModulationFrequency.clear(); // Reset flags
1335  }
1336  }
1337  else
1338  {
1339  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1340  std::cerr << "\t ... Can't find tag 'Modulation'." << std::endl;
1341  return (RET_FAILED | RET_XML_TAG_NOT_FOUND);
1342  }
1343 
1344 //************************************************************************************
1345 // BEGIN LibCameraSensors->Swissranger->AcquireMode
1346 //************************************************************************************
1347  // Subtag element "IntegrationTime" of Xml Inifile
1348  p_xmlElement_Child = NULL;
1349  p_xmlElement_Child = p_xmlElement_Root_SR31->FirstChildElement( "AcquireMode" );
1350  if ( p_xmlElement_Child )
1351  {
1352  int acquireMode = 0;
1353  // read and save value of attribute
1354  if ( p_xmlElement_Child->QueryValueAttribute( "AM_COR_FIX_PTRN", &tempString) != TIXML_SUCCESS)
1355  {
1356  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1357  std::cerr << "\t ... Can't find attribute 'AM_COR_FIX_PTRN' of tag 'AcquireMode'." << std::endl;
1359  }
1360  else
1361  {
1362  if (tempString == "ON") acquireMode |= AM_COR_FIX_PTRN;
1363  }
1364 
1365  if ( p_xmlElement_Child->QueryValueAttribute( "AM_MEDIAN", &tempString) != TIXML_SUCCESS)
1366  {
1367  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1368  std::cerr << "\t ... Can't find attribute 'AM_MEDIAN' of tag 'AcquireMode'." << std::endl;
1370  }
1371  else
1372  {
1373  if (tempString == "ON") acquireMode |= AM_MEDIAN;
1374  }
1375 
1376  if ( p_xmlElement_Child->QueryValueAttribute( "AM_TOGGLE_FRQ", &tempString) != TIXML_SUCCESS)
1377  {
1378  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1379  std::cerr << "\t ... Can't find attribute 'AM_TOGGLE_FRQ' of tag 'AcquireMode'." << std::endl;
1381  }
1382  else
1383  {
1384  if (tempString == "ON") acquireMode |= AM_TOGGLE_FRQ;
1385  }
1386 
1387  if ( p_xmlElement_Child->QueryValueAttribute( "AM_CONV_GRAY", &tempString) != TIXML_SUCCESS)
1388  {
1389  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1390  std::cerr << "\t ... Can't find attribute 'AM_CONV_GRAY' of tag 'AcquireMode'." << std::endl;
1392  }
1393  else
1394  {
1395  if (tempString == "ON") acquireMode |= AM_CONV_GRAY;
1396  }
1397 
1398  if ( p_xmlElement_Child->QueryValueAttribute( "AM_SW_ANF", &tempString) != TIXML_SUCCESS)
1399  {
1400  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1401  std::cerr << "\t ... Can't find attribute 'AM_SW_ANF' of tag 'AcquireMode'." << std::endl;
1403  }
1404  else
1405  {
1406  if (tempString == "ON") acquireMode |= AM_SW_ANF;
1407  }
1408 
1409  if ( p_xmlElement_Child->QueryValueAttribute( "AM_SR3K_2TAP_PROC", &tempString) != TIXML_SUCCESS)
1410  {
1411  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1412  std::cerr << "\t ... Can't find attribute 'AM_SR3K_2TAP_PROC' of tag 'AcquireMode'." << std::endl;
1414  }
1415  else
1416  {
1417  //if (tempString == "ON") acquireMode |= AM_RESERVED0;
1418  }
1419 
1420  if ( p_xmlElement_Child->QueryValueAttribute( "AM_SHORT_RANGE", &tempString) != TIXML_SUCCESS)
1421  {
1422  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1423  std::cerr << "\t ... Can't find attribute 'AM_SHORT_RANGE' of tag 'AcquireMode'." << std::endl;
1425  }
1426  else
1427  {
1428  //if (tempString == "ON") acquireMode |= AM_RESERVED1;
1429  }
1430 
1431  if ( p_xmlElement_Child->QueryValueAttribute( "AM_CONF_MAP", &tempString) != TIXML_SUCCESS)
1432  {
1433  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1434  std::cerr << "\t ... Can't find attribute 'AM_CONF_MAP' of tag 'AcquireMode'." << std::endl;
1436  }
1437  else
1438  {
1439  if (tempString == "ON") acquireMode |= AM_CONF_MAP;
1440  }
1441 
1442  if ( p_xmlElement_Child->QueryValueAttribute( "AM_HW_TRIGGER", &tempString) != TIXML_SUCCESS)
1443  {
1444  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1445  std::cerr << "\t ... Can't find attribute 'AM_HW_TRIGGER' of tag 'AcquireMode'." << std::endl;
1447  }
1448  else
1449  {
1450  if (tempString == "ON") acquireMode |= AM_HW_TRIGGER;
1451  }
1452 
1453  if ( p_xmlElement_Child->QueryValueAttribute( "AM_SW_TRIGGER", &tempString) != TIXML_SUCCESS)
1454  {
1455  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1456  std::cerr << "\t ... Can't find attribute 'AM_SW_TRIGGER' of tag 'AcquireMode'." << std::endl;
1458  }
1459  else
1460  {
1461  if (tempString == "ON") acquireMode |= AM_SW_TRIGGER;
1462  }
1463 
1464  if ( p_xmlElement_Child->QueryValueAttribute( "AM_DENOISE_ANF", &tempString) != TIXML_SUCCESS)
1465  {
1466  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1467  std::cerr << "\t ... Can't find attribute 'AM_DENOISE_ANF' of tag 'AcquireMode'." << std::endl;
1469  }
1470  else
1471  {
1472  if (tempString == "ON") acquireMode |= AM_DENOISE_ANF;
1473  }
1474 
1475  if ( p_xmlElement_Child->QueryValueAttribute( "AM_MEDIANCROSS", &tempString) != TIXML_SUCCESS)
1476  {
1477  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1478  std::cerr << "\t ... Can't find attribute 'AM_MEDIANCROSS' of tag 'AcquireMode'." << std::endl;
1480  }
1481  else
1482  {
1483  if (tempString == "ON") acquireMode |= AM_MEDIANCROSS;
1484  }
1485 
1486  m_RangeCameraParameters.m_AcquireMode.str( " " ); // Clear stringstream
1487  m_RangeCameraParameters.m_AcquireMode.clear(); // Reset flags
1488  m_RangeCameraParameters.m_AcquireMode << acquireMode;
1489  }
1490  else
1491  {
1492  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1493  std::cerr << "\t ... Can't find tag 'AcquireMode'." << std::endl;
1494  return (RET_FAILED | RET_XML_TAG_NOT_FOUND);
1495  }
1496 
1497 //************************************************************************************
1498 // BEGIN LibCameraSensors->Swissranger->CalibrationMethod
1499 //************************************************************************************
1500  // Subtag element "OperationMode" of Xml Inifile
1501  p_xmlElement_Child = NULL;
1502  p_xmlElement_Child = p_xmlElement_Root_SR31->FirstChildElement( "CalibrationMethod" );
1503  if ( p_xmlElement_Child )
1504  {
1505  // read and save value of attribute
1506  if ( p_xmlElement_Child->QueryValueAttribute( "name", &tempString ) != TIXML_SUCCESS)
1507  {
1508  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1509  std::cerr << "\t ... Can't find attribute 'name' of tag 'CalibrationMethod'." << std::endl;
1511  }
1512  if (tempString == "MATLAB") m_CalibrationMethod = MATLAB;
1513  else if (tempString == "MATLAB_NO_Z") m_CalibrationMethod = MATLAB_NO_Z;
1514  else if (tempString == "NATIVE") m_CalibrationMethod = NATIVE;
1515  else
1516  {
1517  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1518  std::cerr << "\t ... Calibration mode " << tempString << " unspecified." << std::endl;
1519  return (RET_FAILED);
1520  }
1521  }
1522  else
1523  {
1524  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1525  std::cerr << "\t ... Can't find tag 'CalibrationMethod'." << std::endl;
1526  return (RET_FAILED | RET_XML_TAG_NOT_FOUND);
1527  }
1528 
1529  }
1530 //************************************************************************************
1531 // END LibCameraSensors->Swissranger
1532 //************************************************************************************
1533  else
1534  {
1535  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1536  std::cerr << "\t ... Can't find tag '" << ss.str() << "'" << std::endl;
1537  return (RET_FAILED | RET_XML_TAG_NOT_FOUND);
1538  }
1539  }
1540 
1541 //************************************************************************************
1542 // END LibCameraSensors
1543 //************************************************************************************
1544  else
1545  {
1546  std::cerr << "ERROR - Swissranger::LoadParameters:" << std::endl;
1547  std::cerr << "\t ... Can't find tag 'LibCameraSensors'." << std::endl;
1548  return (RET_FAILED | RET_XML_TAG_NOT_FOUND);
1549  }
1550  }
1551 
1552 
1553  std::cout << "INFO - Swissranger::LoadParameters:" << std::endl;
1554  std::cout << "\t ... Parsing xml calibration file: Done.\n";
1555 
1556 
1557 
1558  return RET_OK;
1559 }
bool m_CoeffsInitialized
True, when m_CoeffsAx have been initialized.
Definition: Swissranger.h:136
cv::Mat m_intrinsicMatrix
Intrinsic parameters [fx 0 cx; 0 fy cy; 0 0 1].
t_CalibrationMethod m_CalibrationMethod
Calibration method MATLAB, MATLAB_NO_Z or SWISSRANGER.
unsigned long GetProperty(t_cameraProperty *cameraProperty)
cv::Mat m_CoeffsA1
a1 z-calibration parameters. One matrix entry corresponds to one pixel
Definition: Swissranger.h:144
cv::Mat m_CoeffsA2
a2 z-calibration parameters. One matrix entry corresponds to one pixel
Definition: Swissranger.h:145
unsigned long AcquireImages(int widthStepRange, int widthStepGray, int widthStepCartesian, char *RangeImage=NULL, char *IntensityImage=NULL, char *cartesianImage=NULL, bool getLatestFrame=true, bool undistort=true, ipa_CameraSensors::t_ToFGrayImageType grayImageType=ipa_CameraSensors::INTENSITY_32F1)
unsigned long SetProperty(t_cameraProperty *cameraProperty)
cv::Mat m_CoeffsA4
a4 z-calibration parameters. One matrix entry corresponds to one pixel
Definition: Swissranger.h:147
ipa_CameraSensors::t_cameraRole m_CameraRole
Master or slave camera.
float m_Y[SWISSRANGER_COLUMNS *SWISSRANGER_ROWS]
Definition: Swissranger.h:133
unsigned long GetCalibratedZSwissranger(int u, int v, int width, float &zCalibrated)
unsigned long Init(std::string directory, int cameraIndex=0)
Definition: Swissranger.cpp:84
bool m_GrayImageAcquireCalled
Is false, when acquiring gray image has not been called, yet.
Definition: Swissranger.h:137
unsigned long GetCalibratedZMatlab(int u, int v, float zRaw, float &zCalibrated)
float m_Z[SWISSRANGER_COLUMNS *SWISSRANGER_ROWS]
Definition: Swissranger.h:134
unsigned long LoadParameters(const char *filename, int cameraIndex)
unsigned long SetPropertyDefaults()
std::stringstream m_AmplitudeThreshold
their amplitude is lower than the amplitude threshold
cv::Mat m_CoeffsA5
a5 z-calibration parameters. One matrix entry corresponds to one pixel
Definition: Swissranger.h:148
SRCAM m_SRCam
Handle to USB SR3000 camera.
Definition: Swissranger.h:127
unsigned long SaveParameters(const char *filename)
unsigned int m_BufferSize
Number of images, the camera buffers internally.
cv::Mat m_CoeffsA0
a0 z-calibration parameters. One matrix entry corresponds to one pixel
Definition: Swissranger.h:143
boost::shared_ptr< AbstractRangeImagingSensor > AbstractRangeImagingSensorPtr
cv::Mat m_undistortMapX
The output array of x coordinates for the undistortion map.
cv::Mat m_CoeffsA6
a6 z-calibration parameters. One matrix entry corresponds to one pixel
Definition: Swissranger.h:149
unsigned long GetCalibratedXYSwissranger(int u, int v, int width, float &x, float &y)
unsigned long EvaluatePolynomial(double x, int degree, double *coefficients, double *y)
cv::Mat m_undistortMapY
The output array of Y coordinates for the undistortion map.
cv::Mat m_CoeffsA3
a3 z-calibration parameters. One matrix entry corresponds to one pixel
Definition: Swissranger.h:146
bool m_initialized
True, when the camera has sucessfully been initialized.
std::stringstream m_ModulationFrequency
Modulation Frequency. The higher the frequency, the lower the measurable distance.
__DLL_LIBCAMERASENSORS__ AbstractRangeImagingSensorPtr CreateRangeImagingSensor_Swissranger()
Definition: Swissranger.cpp:31
t_RangeCameraParameters m_RangeCameraParameters
Storage for xml configuration file parmeters.
std::stringstream m_Interface
Interface, the camera is connected to (i.e. USB or ETHERNET)
ImgEntry * m_DataBuffer
Image array.
Definition: Swissranger.h:129
#define __DLL_LIBCAMERASENSORS__
float m_X[SWISSRANGER_COLUMNS *SWISSRANGER_ROWS]
Definition: Swissranger.h:132
unsigned long GetCalibratedXYMatlab(int u, int v, float z, float &x, float &y)
bool m_open
True, when the camera has sucessfully been opend.
int LibMesaCallback(SRCAM srCam, unsigned int msg, unsigned int param, void *data)
Definition: Swissranger.cpp:57


cob_camera_sensors
Author(s): Jan Fischer , Richard Bormann
autogenerated on Thu Mar 19 2020 03:23:05