26 #pragma comment( lib, "libMesaSR.lib" )
31 #include "VideoSource_SwissRanger.hh"
39 #include <Image/Camera.hh>
40 #include <Base/Image/ImageConvert.hh>
41 #include <Base/Image/ImageIO.hh>
45 #include <libMesaSR.h>
82 if (bIsOpen_) CloseDevice();
88 int ret = SR_GetVersion(v);
90 ver<<v[3]<<
"."<<v[2]<<
"."<<v[1]<<
"."<<v[0];
97 if(
srCam_== NULL)
return -1;
99 int ret = SR_GetDeviceString(
srCam_,buf,100);
100 device = string(buf);
109 BIASERR(
"Device SwissRanger has been opened already.");
113 ret = GetSoftwareVersion(version);
115 cout<<
"SRMesa Software Version:"<<version<<endl;
120 ret = SR_OpenUSB(&srCam_,serialNumber_);
124 BIASERR(
"OpenDevice of Swissranger not successfull (return:"<< ret<<
") try to reopen.")
127 ResetUsbDeviceConnection_();
130 BIASERR(
"Could not open the SwissRanger device (return:"<< ret<<
")!");
135 Width_ = SR_GetCols(srCam_);
136 Height_ = SR_GetRows(srCam_);
140 BIASERR(
"Image dimension of Swissranger not correct, try to reopen.")
143 ResetUsbDeviceConnection_();
146 BIASERR(
"Connection to Swissranger is not sane. Please restart.");
154 numPics = SR_GetImageList(srCam_,&imgEntryArray);
157 for(
int i = 0; i < numPics; i++){
158 entr = imgEntryArray[i];
160 cout <<
"ImageType: " << entr.imgType << endl;
173 SR_SetIntegrationTime(srCam_,integrationTime_);
175 ret = SR_SetModulationFrequency(srCam_,modulationFrequency_);
176 if(ret != 0) BIASERR(
"Setting modulation Frequency failed.");
177 modulationFrequency_ = SR_GetModulationFrequency(srCam_);
181 string devstring; GetDeviceString(devstring);
182 if (devstring.find(
"SR3000") != string::npos) {
183 camType_ = CT_SR3K_USB;
185 camType_ = CT_SR4K_USB;
188 if(bExternalTrigger_){
190 cout<<
"SR Setting mode with Trigger!"<<endl;
192 ret = SR_SetMode(srCam_,AM_COR_FIX_PTRN|AM_MEDIAN|AM_DENOISE_ANF|AM_CONV_GRAY|AM_HW_TRIGGER|AM_SW_TRIGGER);
198 cout<<
"SR Setting normal mode!"<<endl;
200 ret = SR_SetMode(srCam_,AM_COR_FIX_PTRN|AM_MEDIAN|AM_CONV_GRAY|AM_DENOISE_ANF);
204 BIASERR(
"Opening Swissranger failed!");
215 serialNumber_= camNr;
222 if (SR_Close(srCam_) < 0) {
223 BIASERR(
"Disonnection of Swiss Ranger via USB failed!");
238 val = 0.25f * ((inttime / 0.2f) - 1.0f);
242 val = 0.25f * ((inttime - 0.3f) / 0.1f);
245 BIASERR(
"can not set integration time as camera type is unknown.");
248 if (val < 0 || val > 255) {
249 BIASWARN(
"clipping integration time");
251 return SetIntegrationTime( (
unsigned char)val );
259 inttime = 4.0f * float(integrationTime_+1.0f)*0.2f;
263 inttime = 4.0f * (0.3f+float(integrationTime_)*0.1f);
266 BIASERR(
"can not set integration time as camera type is unknown.");
289 BIASERR(
"VideoSource::InitImage() should be called with uninitialized image");
300 BIASERR(
"VideoSource::InitImage() should be called with uninitialized image");
315 BIASERR(
"GrabSingle called but device not opened!");
319 res=SR_Acquire(srCam_);
321 if(bEnsureLatestFrame_)
322 res+=SR_Acquire(srCam_);
325 if(bExternalTrigger_){
326 BIASERR(
"Reading image from SwissRanger failed. Wait for next trigger.");
329 BIASERR(
"Reading image from SwissRanger failed. Please restart application");
334 SR_GetImageList(srCam_,&imgEntryArray);
336 dataDepth_ = (
const unsigned short*)SR_GetImage(srCam_,0);
337 dataAmp_ = (
const unsigned short*)SR_GetImage(srCam_,1);
339 ConvertRawImageToFloat_(dataDepth_, DepthImgF_);
340 ConvertRawImage_(dataAmp_, ModCoeffImg_);
341 if (bGrabImageReturnsDepth_) {
342 ConvertImageFloatToCharNormalized_(DepthImgF_, image,
true);
344 ConvertImageFloatToCharNormalized_(ModCoeffImg_, image);
355 float normFactor = 0.0f;
357 normFactor = float(255.0f / max_dist_);
361 normFactor = float(255.0f / max);
365 for (
unsigned int y=0; y<dst.
GetHeight(); y++) {
366 for (
unsigned int x=0; x< dst.
GetWidth(); x++) {
367 dstData[y][x] = (
unsigned char)( srcData[y][x] * normFactor );
380 const unsigned short* srcDepthP=data;
382 for (
unsigned int y=0; y<dst.
GetHeight(); y++) {
383 for (
unsigned int x=0; x< dst.
GetWidth(); x++) {
384 float cur = (*srcDepthP)*max_dist_ / (float)0xffff;
399 const unsigned short* srcDepthP=data;
401 float step = (float)0xff / (
float)0xffff;
402 for (
unsigned int y=0; y<dst.
GetHeight(); y++) {
403 for (
unsigned int x=0; x< dst.
GetWidth(); x++) {
404 float cur = (*srcDepthP) * step;
412 integrationTime_ = inttime;
413 return SR_SetIntegrationTime(srCam_, inttime);
417 modulationFrequency_ = dModulationFrequency;
419 return SR_SetModulationFrequency(srCam_, (ModulationFrq)modulationFrequency_);
423 float lightspeed = 299792.485f;
425 std::cout<<
"modulationFrequency_:"<< modulationFrequency_ <<std::endl;
428 switch (modulationFrequency_) {
430 max_dist_ = (lightspeed / 60.0f) / 2.0f;
433 max_dist_ = (lightspeed / 40.0f) / 2.0f;
436 max_dist_ = (lightspeed / 31.0f) / 2.0f;
439 max_dist_ = (lightspeed / 30.0f) / 2.0f;
442 max_dist_ = (lightspeed / 29.0f) / 2.0f;
445 max_dist_ = (lightspeed / 21.0f) / 2.0f;
448 max_dist_ = (lightspeed / 20.0f) / 2.0f;
451 max_dist_ = (lightspeed / 19.0f) / 2.0f;
454 max_dist_ = (lightspeed / 15.0f) / 2.0f;
457 max_dist_ = (lightspeed / 10.0f) / 2.0f;
462 BIASERR(
"Can not set modulation frequency for SwissRanger!");
470 BIASWARN(
"resetting usb device. device will be set to default configuration");
472 struct usb_bus *busses;
474 struct usb_device *dev;
475 struct usb_dev_handle *handle;
482 busses = usb_get_busses();
483 for (bus = busses; bus; bus = bus->next) {
484 for (dev = bus->devices; dev; dev = dev->next) {
485 if ((dev->descriptor.idVendor == 0x0852 || dev->descriptor.idVendor == 0x1ad2) && (dev->descriptor.idProduct == 0x0074 || dev->descriptor.idProduct == 0x0075)) {
487 handle = usb_open(dev);
489 usb_set_configuration(handle, dev->config[0].bConfigurationValue);
490 usb_claim_interface(handle, 0);
virtual void SetSize(int w, int h, int bytesperpixel=1)
Set image size and number of bytes per pixel (e.g.
virtual int PreGrab()
no needed for PreGrab now, does not do anything
int GetDeviceString(std::string &device)
returns the device string of the camera
int GetSoftwareVersion(std::string &version)
returns the version of the used software
Defines a common interface to different devices.
virtual int PostGrab()
no needed for PostGrab now, does not do anything
unsigned short amplitudeThreshold_
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
virtual int InitDepthImage(ImageBase &img)
Init the depth image to grab to.
bool bGrabImageReturnsDepth_
const unsigned short * dataAmp_
void SetColorModel(EColorModel Model)
void ConvertImageFloatToCharNormalized_(const Image< float > src, Image< unsigned char > &dst, bool useMaxDist=false)
void ConvertRawImage_(const unsigned short *data, Image< float > &dst)
void GetMinMaxPixelValue(StorageType &min, StorageType &max, unsigned short int channel=0, unsigned int *mincoo=NULL, unsigned int *maxcoo=NULL) const
returns the minimal and maximal pixel value in channel only Finds minimum and maximum pixel value in ...
unsigned int GetWidth() const
unsigned int serialNumber_
const unsigned short * dataDepth_
void ConvertRawImageToFloat_(const unsigned short *data, Image< float > &dst)
virtual int SetColorModel(BIAS::ImageBase::EColorModel mode)
Select colormodel to use.
virtual int InitImage(ImageBase &img)
Init the grey image to grab to.
ModulationFrq modulationFrequency_
void ReInit(const unsigned int &width, const unsigned int &height, const unsigned int nChannels=1, const enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true, const EColorModel colormodel=CM_Grey)
(Re-)Initialize Image data if required.
VideoSource_SwissRanger()
unsigned int GetHeight() const
virtual int SetIntegrationTime(const unsigned char inttime)
Set IntegrationTime (as uchar 0-255)
int SetModulationFrequency(ModulationFrq dModulationFrequency)
Set the Modulation frequency (from defines.h) MF_40MHz=0, //!<SR3k: maximal range 3...
virtual int GetCapabilities(VideoSourceCapabilities &caps)
Dummy function, does not do anything.
unsigned short distanceOffset_
~VideoSource_SwissRanger()
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
void Release(const bool reset_storage_type=false)
Free the allocated data structures Hands off: Do !!NOT!! change the default of reset_storage_type: Im...
virtual int GetIntegrationTimeMS(float &inttime)
Get IntegrationTime in ms.
unsigned char integrationTime_
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.
virtual int OpenDevice()
try to open first unused PMD-camera
void ResetUsbDeviceConnection_()
uses libusb directly to reset the device in case of failure on open
virtual int CloseDevice()
close an active camera
(8bit) unsigned char image storage type
Checks for VideoSource capabilities.
virtual int GrabSingle(Camera< unsigned char > &image)
Returns the 2D image, and reads depth and modulation coefficients.
unsigned short saturationThreshold_
This is the base class for images in BIAS.
virtual int SetIntegrationTimeMS(float inttime)
Set IntegrationTime in ms (gets clipped to min/max for camera)
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase