26 # error The PMD-cameras can only be run under windows.
30 #include "VideoSource_PMDZess.hh"
38 #include <Image/Camera.hh>
42 #include <defines.hpp>
75 if (bIsOpen_) CloseDevice();
81 BIASERR(
"Device has been opened allready!!!");
86 BIASERR(
"No bitfile for PMDZess given!!!");
95 if (z2D3D_setChip(type_, use2D_, doCalcs_, phaseAlgorithm_)<0) {
96 BIASERR(
"Connection to PMD-Camera via USB failed!");
102 int ret = z2D3D_init(devicePort_.c_str(), bitFile_.c_str(), type_, use2D_,
103 modulationsFrequenz_, 0, doCalcs_, phaseAlgorithm_);
107 ret = z2D3D_getlasterror(message, 200,&errorcode);
108 cout<<
"Error:"<<message<<endl;
109 BIASERR(
"Error initializing camera!!!"<<ret);
138 BIASERR(
"???Unknown PMD-type but init(...) succeeded???");
143 z2D3D_setexpo( 2, 999,1);
145 z2D3D_SetExposureTimeInMS_2D( 10, 1,999 );
148 if (z2D3D_SetApplicationMode(1) < 0) {
149 BIASERR(
"Error setting application-mode 1!!!");
151 if (z2D3D_deinit() < 0)
152 BIASERR(
"Disonnection of PMD-Camera via USB failed!");
158 unsigned long mirrorRotOpts = 0;
159 if (z2D3D_MirrorRotOpts(&mirrorRotOpts , 1) < 0) {
160 BIASERR(
"Error setting mirror-modes to none!!!");
162 if (z2D3D_deinit() < 0)
163 BIASERR(
"Disonnection of PMD-Camera via USB failed!");
169 if (z2D3D_Scale(1) < 0) {
170 BIASERR(
"Error activating metric depth-output!!!");
172 if (z2D3D_deinit() < 0)
173 BIASERR(
"Disonnection of PMD-Camera via USB failed!");
179 if (z2D3D_Prepare(1) < 0) {
180 BIASERR(
"Error reserving memory for PMD-library!!!");
182 if (z2D3D_deinit() < 0)
183 BIASERR(
"Disonnection of PMD-Camera via USB failed!");
188 dist_ =
new double[Width_*Height_*ColorChannels_];
189 mod_ =
new double[Width_*Height_*ColorChannels_];
191 new signed short[Width_*Height_*ColorChannels_];
193 new signed short[((Width_*Height_+4)*2)*phaseAlgorithm_];
195 new unsigned char[Width2D_*Height2D_*ColorChannels_];
197 if ((dist_ == NULL)||(mod_ == NULL)||(grey_ == NULL)||
198 (total_ == NULL)||(grey2D_ == NULL))
200 BIASERR(
"Error allocating memory for temp-images!!!");
202 if (z2D3D_deinit() < 0)
203 BIASERR(
"Disonnection of PMD-Camera via USB failed!");
227 std::stringstream str(
"USB");
229 devicePort_ = str.str();
237 BIASERR(
"Cannot close device, it has not been opened successfully!!!");
241 if (z2D3D_deinit() < 0) {
242 BIASERR(
"Disonnection of PMD-Camera via USB failed!");
270 BIASERR(
"VideoSource::InitImage() should be called with uninitialized image");
280 BIASERR(
"VideoSource::InitImage() should be called with uninitialized image");
290 unsigned long f = (
unsigned long)(dModulationFrequency);
292 modulationsFrequenz_ = f;
304 return modulationsFrequenz_;
310 unsigned long value, prescaler;
313 value =(
unsigned long)exptime;
315 return z2D3D_setexpo(value, prescaler, value);
319 unsigned long *value =
new unsigned long;
320 unsigned long *value2 =
new unsigned long;
321 unsigned long *prescaler =
new unsigned long;
323 if (z2D3D_getexpo(value, prescaler, value2) < 0)
324 BIASERR(
"Error getting shutter from cam!");
327 float res = float(*value) * (float(*prescaler) + 1.0f) / 1000.0f;
337 unsigned long rowtime, frametime;
338 unsigned long tmp = (
unsigned long)(exptime * 1000.0);
340 rowtime = (
unsigned long)(rint(tmp/10.0));
341 frametime = (
unsigned long)(exptime) / 5;
349 cout<<
"Setting rowtime:"<<rowtime<<
" frametime:"<<frametime<<endl;
350 int ret = z2D3D_SetExposureTimeInMS_2D(rowtime, frametime, 999);
354 ret = z2D3D_getlasterror(message, 200, &errorcode);
355 cout<<
"Error:"<<message<<endl;
362 unsigned long *rowtime =
new unsigned long;
363 unsigned long *frametime =
new unsigned long;
364 unsigned long *prescaler =
new unsigned long;
365 if (z2D3D_GetExposureTimeInMS_2D(rowtime, frametime, prescaler) < 0){
366 BIASERR(
"Error getting shutter from 2D-cam!");
369 z2D3D_getlasterror(message, 200,&errorcode);
370 cout<<
"Error:"<<message<<endl;
373 cout<<
"getting rowtime:"<<*rowtime<<
" frametime:"<<*frametime<<endl;
375 float res = float(*frametime) * 5.0f + 0.01f * float(*rowtime);
385 unsigned long gainUL = (
unsigned long)gain;
386 int ret = z2D3D_SetGain2D(gainUL,gainUL,gainUL,gainUL,gainUL);
391 unsigned long * gain =
new unsigned long;
392 unsigned long * gainblue=
new unsigned long;
393 unsigned long * gainred=
new unsigned long;
394 unsigned long * gaingreen1=
new unsigned long;
395 unsigned long * gaingreen2=
new unsigned long;
396 int ret = z2D3D_GetGain2D(gain,gainblue,gainred,gaingreen1,gaingreen2);
403 float result = (float)(*gain);
409 int res = z2D3D_CalcSinglePhase(0);
422 raw =
new signed short[Width_*Height_*ColorChannels_];
429 res = z2D3D_Fetch1(0,-1,raw,0,0,0,0,0,0);
440 if (z2D3D_Do(-1) < 0) {
441 BIASERR(
"Error calculating next image!!!");
446 res = z2D3D_Fetch(0, dist_, mod_, grey_, total_, grey2D_);
449 BIASERR(
"Error getting image data from PMD-lib!!!");
454 DepthImageFloatFromDouble_(dist_, DepthImg_);
455 ImageFloatFromDouble_(mod_, ModCoeffImg_);
456 ImageUcharFromShort_(grey_, image);
457 Convert2DImage_(grey2D_,img2D_);
469 double min = DBL_MAX;
470 double max = DBL_MIN;
472 if (*pus<min) min = *pus;
473 if (*pus>max) max = *pus;
476 double divisor = max - min;
481 for (
unsigned int y=0; y<dst.
GetHeight(); y++) {
482 for (
int x=0; x<int(dst.
GetWidth()); x++) {
484 (
unsigned char)(255.0*((*pus)-min)/divisor);
500 signed short* pus=data;
501 signed short min = *pus;
502 signed short max = *pus;
504 if (*pus<min) min = *pus;
505 if (*pus>max) max = *pus;
508 double divisor = double(max - min);
513 for (
unsigned int y=0; y<dst.
GetHeight(); y++) {
514 for (
int x=0; x<int(dst.
GetWidth()); x++) {
516 (
unsigned char)(255.0*(double(*pus)-min)/divisor);
531 double f = 20000000.0;
532 double c = 299792458.0*1000.0;
533 float m = float(c/f/2);
536 for (
unsigned int y=0; y<dst.
GetHeight(); y++) {
537 for (
int x=0; x<int(dst.
GetWidth()); x++) {
538 puc[y][int(dst.
GetWidth())-1-x] = (
float)(*pus);
539 while(puc[y][
int(dst.
GetWidth())-1-x]<0.0){
542 while(puc[y][
int(dst.
GetWidth())-1-x]>m){
560 for (
unsigned int y=0; y<dst.
GetHeight(); y++) {
561 for (
int x=0; x<int(dst.
GetWidth()); x++) {
562 puc[y][int(dst.
GetWidth())-1-x] = (
float)(*pus);
576 unsigned char* srcDatap=data;
578 for (
unsigned int y=0; y<dst.
GetHeight(); y++) {
579 for (
unsigned int x=0; x< dst.
GetWidth(); x++) {
580 dstData[y][int(dst.
GetWidth())-1-x] = (*srcDatap);
int SetGain2D(float g)
Set gain to g with g[dB].
virtual void SetSize(int w, int h, int bytesperpixel=1)
Set image size and number of bytes per pixel (e.g.
unsigned int modulationsFrequenz_
int SetModulationFrequency(int dModulationFrequency)
Defines a common interface to different devices.
int CaptureSinglePhase(Camera< unsigned char > &image)
Capture a single phase image only.
int GetModulationFrequency()
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
void Convert2DImage_(unsigned char *data, Image< unsigned char > &dst)
int SetShutter2D(float exptime)
Set shutter (exposure time) to exptime in seconds [==] for 2D-chip.
void SetColorModel(EColorModel Model)
unsigned int GetWidth() const
void DepthImageFloatFromDouble_(double *data, Image< float > &dst)
virtual int CloseDevice()
virtual int SetColorModel(BIAS::ImageBase::EColorModel mode)
Select colormodel to use.
virtual int PreGrab()
Do last preparations before grabbing (e.g. start ISO transfer)
unsigned int GetHeight() const
void ImageUcharFromDouble_(double *data, Image< unsigned char > &dst)
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 InitImage(ImageBase &img)
virtual int OpenDevice()
selects the first available device to open (e.g.
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.
void ImageUcharFromShort_(signed short *data, Image< unsigned char > &dst)
(8bit) unsigned char image storage type
virtual float GetShutter3D()
virtual int GrabSingle(Camera< unsigned char > &image)
Returns the 2D image, and reads depth and modulation coefficients.
This is the base class for images in BIAS.
virtual int Init2DImage(ImageBase &img)
virtual int PostGrab()
Stop anything started in PreGrab()
void SetZero()
zeroes the image
virtual int SetShutter3D(float exptime)
Set shutter (exposure time) to exptime in seconds [==] for PMD-chip.
void ImageFloatFromDouble_(double *data, Image< float > &dst)
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase