Swissranger.h
Go to the documentation of this file.
00001 /****************************************************************
00002 *
00003 * Copyright (c) 2010
00004 *
00005 * Fraunhofer Institute for Manufacturing Engineering
00006 * and Automation (IPA)
00007 *
00008 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00009 *
00010 * Project name: care-o-bot
00011 * ROS stack name: cob_driver
00012 * ROS package name: cob_camera_sensors
00013 * Description: Platform independent interface to MESA Swissranger camera.
00014 * Implementation depends on libusbSR library.
00015 *
00016 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00017 *
00018 * Author: Jan Fischer, email:jan.fischer@ipa.fhg.de
00019 * Supervised by: Jan Fischer, email:jan.fischer@ipa.fhg.de
00020 *
00021 * Date of creation: July 2008
00022 * ToDo:
00023 *
00024 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00025 *
00026 * Redistribution and use in source and binary forms, with or without
00027 * modification, are permitted provided that the following conditions are met:
00028 *
00029 * * Redistributions of source code must retain the above copyright
00030 * notice, this list of conditions and the following disclaimer.
00031 * * Redistributions in binary form must reproduce the above copyright
00032 * notice, this list of conditions and the following disclaimer in the
00033 * documentation and/or other materials provided with the distribution.
00034 * * Neither the name of the Fraunhofer Institute for Manufacturing
00035 * Engineering and Automation (IPA) nor the names of its
00036 * contributors may be used to endorse or promote products derived from
00037 * this software without specific prior written permission.
00038 *
00039 * This program is free software: you can redistribute it and/or modify
00040 * it under the terms of the GNU Lesser General Public License LGPL as
00041 * published by the Free Software Foundation, either version 3 of the
00042 * License, or (at your option) any later version.
00043 *
00044 * This program is distributed in the hope that it will be useful,
00045 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00046 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00047 * GNU Lesser General Public License LGPL for more details.
00048 *
00049 * You should have received a copy of the GNU Lesser General Public
00050 * License LGPL along with this program.
00051 * If not, see <http://www.gnu.org/licenses/>.
00052 *
00053 ****************************************************************/
00054  
00060 
00061 #ifndef __IPA_SWISSRANGER_H__
00062 #define __IPA_SWISSRANGER_H__
00063 
00064 #include "StdAfx.h"
00065 
00066 // Windows
00067 #ifdef _WIN32
00068         // Windows with MinGW
00069         #ifdef __MINGW__
00070                 typedef short __wchar_t;
00071         #endif
00072 #endif
00073 
00074 // Linux
00075 #ifdef __LINUX__
00076 typedef unsigned long DWORD;
00077 #endif
00078 
00079 #ifdef __LINUX__
00080         #include <cob_camera_sensors/AbstractRangeImagingSensor.h>
00081 #else
00082         #include <cob_driver/cob_camera_sensors/common/include/cob_camera_sensors/AbstractRangeImagingSensor.h>
00083 #endif
00084 
00085 #include <stdio.h>
00086 #include <math.h>
00087 #include <sstream>
00088 #include <assert.h>
00089 #include <libMesaSR.h>
00090 
00091 namespace ipa_CameraSensors {
00092 
00093 // former SR31Consts.h entries
00094 #define SAFE_FREE(p)       { if(p) { delete (p); (p)=0; } }
00095 #define SWISSRANGER_COLUMNS 176
00096 #define SWISSRANGER_ROWS 144
00097 
00104 int LibMesaCallback(SRCAM srCam, unsigned int msg, unsigned int param, void* data);
00105 
00110 class __DLL_LIBCAMERASENSORS__ Swissranger : public AbstractRangeImagingSensor
00111 {
00112 public:
00113 
00114         Swissranger();
00115         ~Swissranger();
00116 
00117         //*******************************************************************************
00118         // AbstractRangeImagingSensor interface implementation
00119         //*******************************************************************************
00120 
00121         unsigned long Init(std::string directory, int cameraIndex = 0);
00122 
00123         unsigned long Open();
00124         unsigned long Close();
00125 
00126         unsigned long SetProperty(t_cameraProperty* cameraProperty);
00127         unsigned long SetPropertyDefaults();
00128         unsigned long GetProperty(t_cameraProperty* cameraProperty);
00129 
00130         unsigned long AcquireImages(int widthStepRange, int widthStepGray, int widthStepCartesian, char* RangeImage=NULL, char* IntensityImage=NULL,
00131                 char* cartesianImage=NULL, bool getLatestFrame=true, bool undistort=true,
00132                 ipa_CameraSensors::t_ToFGrayImageType grayImageType = ipa_CameraSensors::INTENSITY_32F1);
00133         unsigned long AcquireImages(cv::Mat* rangeImage = 0, cv::Mat* grayImage = 0,
00134                 cv::Mat* cartesianImage = 0, bool getLatestFrame = true, bool undistort = true,
00135                 ipa_CameraSensors::t_ToFGrayImageType grayImageType = ipa_CameraSensors::INTENSITY_32F1);
00136 
00137         unsigned long SaveParameters(const char* filename);
00138 
00139         bool isInitialized() {return m_initialized;}
00140         bool isOpen() {return m_open;}
00141 
00142 private:
00143         //*******************************************************************************
00144         // Camera specific members
00145         //*******************************************************************************
00146 
00147         unsigned long GetCalibratedZMatlab(int u, int v, float zRaw, float& zCalibrated);
00148         unsigned long GetCalibratedZSwissranger(int u, int v, int width, float& zCalibrated);
00149         unsigned long GetCalibratedXYMatlab(int u, int v, float z, float& x, float& y);
00150         unsigned long GetCalibratedXYSwissranger(int u, int v, int width, float& x, float& y);
00151 
00157         unsigned long LoadParameters(const char* filename, int cameraIndex);
00158 
00162         unsigned long SetParameters();
00163 
00164         SRCAM m_SRCam;                   
00165         int m_NumOfImages;               
00166         ImgEntry* m_DataBuffer;  
00167 
00168         // Stores for cartesian data, when native swissranger calibration is used
00169         float m_X[SWISSRANGER_COLUMNS * SWISSRANGER_ROWS];
00170         float m_Y[SWISSRANGER_COLUMNS * SWISSRANGER_ROWS];
00171         float m_Z[SWISSRANGER_COLUMNS * SWISSRANGER_ROWS];
00172 
00173         bool m_CoeffsInitialized; 
00174         bool m_GrayImageAcquireCalled; 
00175 
00180         cv::Mat m_CoeffsA0; 
00181         cv::Mat m_CoeffsA1; 
00182         cv::Mat m_CoeffsA2; 
00183         cv::Mat m_CoeffsA3; 
00184         cv::Mat m_CoeffsA4; 
00185         cv::Mat m_CoeffsA5; 
00186         cv::Mat m_CoeffsA6; 
00187 };
00188 
00191 __DLL_LIBCAMERASENSORS__ AbstractRangeImagingSensorPtr CreateRangeImagingSensor_Swissranger();
00192 
00193 } // End namespace ipa_CameraSensors
00194 #endif // __IPA_SWISSRANGER_H__
00195 
00196 


cob_camera_sensors
Author(s): Jan Fischer
autogenerated on Sun Oct 5 2014 23:07:54