25 #include "VideoSource_PMD.hh"
33 #include <Image/Camera.hh>
34 #include <Base/Image/ImageConvert.hh>
35 #include <Base/Image/ImageIO.hh>
69 res = pmdOpenProcessingPlugin(&
handle_, plugin.c_str(),
"");
71 BIASERR(
"could not open processing plugin" << endl);
94 BIASERR(
"could not open source plugin" << endl);
101 BIASERR(
"Pmd Update failed from PMDTec Camera");
106 BIASERR(
"Data description retrieval failed from PMDTec Camera");
118 unsigned int sourceDataSize =
datadesc_.size;
122 sourceData.
Init(sourceDataSize, 1, 1);
131 BIASERR(
"call OpenDevice(...) or OpenSourcePlugin(...) first ");
141 BIASERR(
"closing processing plugin failed");
160 PMDDataDescription dd;
162 if (metaData != NULL) {
165 BIASERR(
"no meta data for distance calculation found");
172 BIASERR(
"no meta data for distance calculation found");
177 BIASERR(
"call OpenProcessingPlugin first " << endl);
187 PMDDataDescription dd;
189 if (metaData != NULL) {
192 BIASERR(
"no meta data for distance calculation found");
200 BIASERR(
"no meta data for distance calculation found");
205 BIASERR(
"call OpenProcessingPlugin first " << endl);
214 PMDDataDescription dd;
216 if (metaData != NULL) {
219 BIASERR(
"no meta data for distance calculation found");
227 BIASERR(
"no meta data for distance calculation found");
232 BIASERR(
"call OpenProcessingPlugin first " << endl);
243 unsigned int width = dd.img.numColumns;
244 unsigned int height = dd.img.numRows;
249 depthImage.
Init(width, height, 1);
253 * height *
sizeof(float), dd, sourceData);
255 BIASERR(
"could not retrieve distances from the source data"<<endl);
259 BIASERR(
"call OpenProcessingPlugin first " << endl);
270 unsigned int width = dd.img.numColumns;
271 unsigned int height = dd.img.numRows;
276 ampImage.
Init(width, height, 1);
280 * height *
sizeof(float), dd, sourceData);
282 BIASERR(
"could not retrieve amplitudes from the source data"<<endl);
286 BIASERR(
"call OpenProcessingPlugin first " << endl);
295 unsigned int width = dd.img.numColumns;
296 unsigned int height = dd.img.numRows;
301 intImage.
Init(width, height, 1);
305 * height *
sizeof(float), dd, sourceData);
307 BIASERR(
"could not retrieve intensities from the source data"<<endl);
311 BIASERR(
"call OpenProcessingPlugin first " << endl);
321 BIASERR(
"Device PMDTec Camera has been opened already.");
334 pmdGetLastError(0, err, 256);
335 BIASERR(
"Connection to PMDTec Camera failed, error:"<<err);
341 BIASERR(
"Data retrieval failed from PMDTec Camera");
348 BIASERR(
"Failed to receive device parameters from PMDTec Camera");
353 cout <<
"Sensor Width: " <<
datadesc_.img.numColumns << endl;
354 cout <<
"Sensor Height: " <<
datadesc_.img.numRows << endl;
362 BIASERR(
"Failed to receive integration time from PMDTec Camera " << ret);
368 BIASERR(
"Failed to receive modulation freq from PMDTec Camera");
379 cout <<
"IntegrationTime [ms]: " << inttime << endl;
384 cout <<
"MaxDist: " <<
max_dist_ << endl;
394 BIASWARN(
"given cam number is ignored!");
401 serialNumber_ = serialNumber;
408 if (!(bIsOpen_ || sourcePluginIsOpen_ || procPluginIsOpen_)) {
409 BIASERR(
"Cannot close device, it has not been opened successfully!!!");
413 int ret = pmdClose(handle_);
415 BIASERR(
"Disconnection of CamCube via USB failed!");
420 sourcePluginIsOpen_ =
false;
421 procPluginIsOpen_ =
false;
423 cout <<
"Closed PMDTec CamCube" << endl;
440 img.
Init(Width_, Height_, 1, st);
446 if (bIsOpen_ || sourcePluginIsOpen_) {
448 int res = pmdUpdate(handle_);
452 BIASERR(
"Frame could not be acquired");
457 res = pmdGetSourceData(handle_, sourceData, size);
461 BIASERR(
"Could not get source data");
465 BIASERR(
"call OpenDevice(...) or OpenSourcePlugin(...) first ");
474 BIASERR(
"GrabSingle called but device not opened!");
478 if (pmdUpdate(handle_) != PMD_OK) {
479 BIASERR(
"Frame could not be acquired");
483 if (pmdGetAmplitudes(handle_, idaTmp_, bufSz_) != PMD_OK) {
484 BIASERR(
"GetAmplitudes failed");
487 FlopImage_(idaTmp_, idaMCIF_);
489 if (pmdGetDistances(handle_, idaTmp_, bufSz_) != PMD_OK) {
490 BIASERR(
"GetDistances failed");
493 FlopImage_(idaTmp_, idaDIF_);
495 if (pmdGetIntensities(handle_, idaTmp_, bufSz_) != PMD_OK) {
496 BIASERR(
"GetIntensities failed");
499 FlopImage_(idaTmp_, idaIIF_);
501 unsigned int pixels = DepthImgF_.GetPixelCount();
502 for (
unsigned int i = 0; i < pixels; i++) {
504 idaDIF_[i] *= 1000.0f;
506 idaDI_[i] = (
unsigned char) (idaDIF_[i] * 255.0f / max_dist_);
508 if (bGrabImageReturnsDepth_)
509 tmpScale_ = DepthImgF_;
511 tmpScale_ = ModCoeffImgF_;
512 tmpScale_.ScaleShiftBetween(0, 255);
527 unsigned time = inttime / 4;
530 if (pmdGetValidIntegrationTime(handle_, &result, 0, CloseTo, time)
532 BIASERR(
"Error getting a valid integration time");
535 if (time != result) {
536 BIASWARN(
"Camera does not allow " << inttime <<
" as integration time. Setting to " << result*4 <<
" instead!");
538 if (pmdSetIntegrationTime(handle_, 0, result) != PMD_OK) {
539 BIASERR(
"Error setting integration time");
542 integrationTime_ = result;
550 if (pmdGetValidModulationFrequency(handle_, &result, 0, CloseTo,
551 dModulationFrequency) != PMD_OK) {
552 BIASERR(
"Error getting a valid modulation frequency");
555 if (dModulationFrequency != result) {
556 BIASWARN(
"Camera does not allow " << dModulationFrequency <<
" as modulation frequency. Setting to " << result <<
" instead!");
559 if (pmdSetModulationFrequency(handle_,0 , result) != PMD_OK) {
560 BIASERR(
"Error setting modulation frequency");
563 modulationFrequency_ = result;
569 float in_meters = float(in_millimeters) / 1000.0f;
572 s <<
"SetSoftOffset " << in_meters;
573 if (pmdSourceCommand(handle_, 0, 0, s.str().c_str()) != PMD_OK) {
574 BIASERR(
"setting distance offset failed");
577 distanceOffset_ = in_millimeters;
583 if (pmdSourceCommand(handle_, sn, 16,
"GetSerialNumber") != PMD_OK) {
584 BIASERR(
"error retrieving serial number");
592 const unsigned int UpperLeftY,
const unsigned int Width,
593 const unsigned int Height) {
596 s <<
"SetROI " << UpperLeftX <<
" " << UpperLeftY <<
" " << Width <<
" "
598 if (pmdSourceCommand(handle_, 0, 0, s.str().c_str()) != PMD_OK) {
599 BIASERR(
"error setting ROI");
611 s <<
"SetFOV " << fov;
612 if (pmdSourceCommand(handle_, 0, 0, s.str().c_str()) != PMD_OK) {
613 BIASERR(
"error setting FOV");
620 float lightspeed = 299792485.0f;
621 max_dist_ = 1000.0f * (lightspeed / float(modulationFrequency_)) / 2.0f;
632 bufSz_ = Width_ * Height_ *
sizeof(float);
634 idaDIF_ = DepthImgF_.GetImageData();
635 idaMCIF_ = ModCoeffImgF_.GetImageData();
636 idaIIF_ = IntensityImgF_.GetImageData();
638 idaDI_ = DepthImg_.GetImageData();
639 idaII_ = IntensityImg_.GetImageData();
641 idaTmp_ = tmpImg_.GetImageData();
646 for (
int y = 0; y < Height_; y++) {
647 for (
int x = 0; x < Width_; x++) {
648 dst[y * Width_ + x] = src[y * Width_ + Width_ - x - 1];
667 ret = pmdGetIntegrationTime(
handle_, &inttime, 0);
683 val = (unsigned)rint(val/1000.0f);
702 res = pmdSourceCommand(
handle_, 0, 0,
"SetExposureMode SMB");
706 BIASERR(
"could not set exposure mode to smb");
712 res = pmdSourceCommand(
handle_, 0, 0,
"SetExposureMode Normal");
716 BIASERR(
"could not set exposure mode to Normal");
724 BIASERR(
"Device note opened ! Call OpenDevice(...) first !");
782 BIASWARNONCE(
"Images of different storage type!");
794 BIASERR(
"Always generating new UUIDS for PMD images");
795 BIASWARNONCE(
"Not implemented!");
801 BIASWARN(
"To be implemented!");
810 pmdSourceCommand (
handle_, 0, 0,
"SetFPNCalibration On");
812 pmdSourceCommand (
handle_, 0, 0,
"SetFPNCalibration Off");
817 BIASERR(
"device is not opened, call OpenDevice first \n");
827 BIASERR(
"call OpenDevice first" << std::endl);
EColorModel
These are the most often used color models.
PMDDataDescription & GetDataDescription()
void Release()
reimplemented from ImageBase
virtual void SetSize(int w, int h, int bytesperpixel=1)
Set image size and number of bytes per pixel (e.g.
bool IsProcessingPluginOpen()
virtual int SetIntegrationTime(const unsigned int inttime)
Set IntegrationTime.
virtual int PostGrab()
Stop anything started in PreGrab()
PMDDataDescription datadesc_
void SetProcessingPlugin(std::string plugin)
only set the plugin to be opened at OpenDevice
int GetDistanceOffset(unsigned int &millimeters)
Defines a common interface to different devices.
int GrabSingleModCoeff(Camera< float > &image)
Returns the amplitude image.
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
virtual int SetIntegrationTimeMS(const unsigned int inttime)
Set IntegrationTime.
void SetSourcePlugin(std::string plugin)
only set the plugin to be opened at OpenDevice
void SetColorModel(EColorModel Model)
int length
number of bytes used by the data block
void SetGenerateNewUIDs(bool s)
int SetFPNCalibrationOn(bool on)
EXPOSURE_MODE GetExposureMode()
unsigned int GetWidth() const
virtual int PreGrab()
Do last preparations before grabbing (e.g. start ISO transfer)
virtual int GrabSingle(Camera< unsigned char > &image)
Returns the 2D image, and reads depth and modulation coefficients.
BIAS::Camera< float > ModCoeffImgF_
virtual int SetColorModel(BIAS::ImageBase::EColorModel mode)
Select colormodel to use.
char * data
pointer to block of data
int SetExposureMode(EXPOSURE_MODE mode)
bool bGrabImageReturnsDepth_
unsigned int integrationTime_
unsigned int modulationFrequency_
int GetModulationFrequency(unsigned int &val)
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
int SetDistanceOffset(const unsigned int in_millimeters)
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
std::string procPluginPath_
int SetROI(const unsigned int UpperLeftX, const unsigned int UpperLeftY, const unsigned int Width, const unsigned int Height)
unsigned int GetHeight() const
virtual int OpenDevice()
selects the first available device to open (e.g.
BIAS::Camera< float > DepthImgF_
virtual ~VideoSource_PMD()
The image template class for specific storage types.
int CalcIntensitiesFromSourceData(BIAS::Image< char > &sourceData, BIAS::Image< float > &intImage)
BIAS::Camera< float > IntensityImgF_
int OpenProcessingPlugin(std::string plugin=BIAS_PMD_PMDTec_PROCPLUGIN)
Open the processing plugin.
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
int InitImage_(ImageBase &img, ImageBase::EStorageType st, ImageBase::EColorModel cm)
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
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...
int OpenSourcePlugin(std::string serial, std::string plugin=BIAS_PMD_PMDTec_SOURCEPLUGIN)
Open the source plugin.
virtual int GetIntegrationTimeMS(unsigned int &val)
Get the IntegrationTime in milliseconds.
int SetFOV(const float fov)
virtual int CloseDevice()
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.
int GrabSingleIntensity(Camera< float > &image)
Returns the amplitude image.
int GetSerialNumber(std::string &serial)
void EnsureLatestFrame(const bool ensure)
int SetModulationFrequency(const unsigned int dModulationFrequency)
virtual int GetIntegrationTime(unsigned int &val)
Get the IntegrationTime.
void FlopImage_(float *src, float *dst)
enum EStorageType GetStorageType() const
(8bit) unsigned char image storage type
bool IsSourcePluginOpen()
int CalcDistancesFromSourceData(BIAS::Image< char > &sourceData, BIAS::Image< float > &depthImage)
int GrabSourceData(char *sourceData, unsigned int size)
std::string serialNumber_
int GrabSingleDepth(Camera< float > &image)
Returns the depth image.
void SetMetaData(const MetaData &m)
This is the base class for images in BIAS.
int CalcAmplitudesFromSourceData(BIAS::Image< char > &sourceData, BIAS::Image< float > &Image)
Depth images A: separated for now.
unsigned int distanceOffset_
std::string sourcePluginPath_
this is a chunk of metadata, also see MetaData
int CloseProcessingPlugin()
Close the processing plugin.