27 #include <Base/Common/W32Compat.hh>
34 #include "VideoSource_DiskPMD.hh"
35 #include <Base/Image/ImageIO.hh>
36 #include <Image/Camera.hh>
38 #include <Base/Common/BIASpragma.hh>
39 #include <Base/Common/FileHandling.hh>
59 BIASERR(
"use OpenDevice(const vector<string> &FileNames)");
70 vecImgModCoeff_.clear();
71 vecMetaData2D_.clear();
72 vecMetaDataDepth_.clear();
76 BIASDOUT(D_VSO_DISK,
"FileName : "<<FileName);
79 vecMetaData2D_, vecMetaDataDepth_)!=0)
81 BIASERR(
"unable to read "<<FileName);
84 if (vecImg2D_.size()>0) {
85 Width_ = vecMetaData2D_[0].width;
86 Height_ = vecMetaData2D_[0].height;
87 ColorChannels_ = vecMetaData2D_[0].channels;
88 ColorMode_ = vecImg2D_[0].GetColorModel();
89 BytesPerPixel_ = vecImg2D_[0].GetDepth();
91 BIASERR(
"No frames in file "<<FileName);
95 for (
unsigned int i=0; i<vecMetaData2D_.size(); i++) {
98 FileNames_.push_back(ss.str().c_str());
101 CompleteInitialized_ =
true;
115 BIASDOUT(D_VSO_DISK,
"FileNames[0] : "<<FileNames[0]);
118 Img2D, ImgDepth, ImgModCoeff,
119 MetaData2D, MetaDataDepth)!=0) {
120 BIASERR(
"unable to read "<<FileNames[0]);
124 Width_ = MetaData2D.
width;
125 Height_ = MetaData2D.
height;
126 ColorChannels_ = MetaData2D.
channels;
131 for (vector<string>::const_iterator i = FileNames.begin();
132 i != FileNames.end();i++){
133 FileNames_.push_back(*i);
136 CompleteInitialized_ =
true;
145 BIASDOUT(D_VSO_DISK,
"VideoSource_DiskPMD::GrabSingle()");
148 BIASERR(
"VideoSource_Disk::GrabSingle(): VideoSource Object not active, use PreGrab()");
153 BIASERR(
"VideoSource_Disk::GrabSingle(): VideoSource Object is already grabbing()");
159 if (vecImg2D_.size()==0) {
160 if (ActiveFrame_ == FileNames_.size()){
161 BIASERR(
"VideoSource_DISK: End of input. SetLoop(true) or Rewind()");
165 if (
PMDImageIO::Load(FileNames_[ActiveFrame_], image, DepthImg_, ModCoeffImg_,
166 MetaData2D, MetaDataDepth)<0) {
167 BIASERR(
"VideoSource_Disk::GrabSingle(): Unable to read image: "
168 << FileNames_[ActiveFrame_]);
172 if (ActiveFrame_ == vecImg2D_.size()){
173 BIASERR(
"VideoSource_DISK: End of input. SetLoop(true) or Rewind()");
180 MetaData2D = vecMetaData2D_[ActiveFrame_];
181 MetaDataDepth = vecMetaDataDepth_[ActiveFrame_];
194 vector<double> UndistCoeff2D(4,0.0);
200 vector<double> UndistCoeffDepth(4,0.0);
209 radDistType,UndistCoeff2D);
212 radDistType,UndistCoeffDepth);
216 DepthImg_.SetProj(ProjDepth);
217 DepthImg_.UpdateMetaData();
218 DepthImg_.SetUID(image.
GetUID());
219 ModCoeffImg_.SetProj(ProjDepth);
220 ModCoeffImg_.UpdateMetaData();
221 ModCoeffImg_.SetUID(image.
GetUID());
224 if (FrameCounterAsTimeStamp_) image.
SetTime(ActiveFrame_,0);
227 gettimeofday(&tv, NULL);
228 image.
SetTime(tv.tv_sec,tv.tv_usec);
230 if(ActiveFrame_<FileNames_.size()-1){
231 BIASDOUT(D_VSO_DISK,
"GrabSingle() "<<ActiveFrame_<<
" "<<
232 FileNames_[ActiveFrame_]);
237 BIASDOUT(D_VSO_DISK,
"GrabSingle() restarting with first file");
242 BIASDOUT(D_VSO_DISK,
"leaving GrabSingle()");
244 double secPerFrame=1.0/FramesPerSecond_;
251 while (timer_.GetRealTime()<=(1E06*secPerFrame)) {
static int LoadFromXML(const std::string &FileName, Image< unsigned char > &Img2D, Image< float > &ImgDepth, Image< float > &ImgModCoeff, PMDImageMetaData &MetaData2D, PMDImageMetaData &MetaDataDepth)
Load a PMD-data 2d/3d-image from PMDtec's XMK format.
unsigned int GetDepth() const
returns the bytes per channel, which is the sizeof(StorageType) Should match GetSizeDepth(GetStorageT...
virtual int GrabSingle(Camera< unsigned char > &image)
Returns the 2D image, and reads depth and modulation coefficients.
virtual int OpenDevice()
selects the first available device to open (e.g.
const BIAS::UUID & GetUID() const
returns the UUID of the image
virtual ~VideoSource_DiskPMD()
Represents 3d pose transformations, parametrized as Euclidean translation and unit quaternion orienta...
static std::string Basename(const std::string &fullname)
Get file base name without path from given path and filename.
This class hides the underlying projection model, like projection matrix, spherical camera...
static int Load(const std::string &FileName, uint8 *&Img2D, uint16 *&ImgDepth, uint16 *&ImgModCoeff, PMDImageMetaData &MetaData2D, PMDImageMetaData &MetaDataDepth)
Load a PMD-data 2d/3d-tiff image from disk.
int SetProj(const Projection &Proj)
void SetUID(const BIAS::UUID &id)
enum EColorModel GetColorModel() const
int UpdateMetaData()
copy P_ and co.
static std::string Suffix(const std::string &fullname)
Get file suffix (including dot!) from given path and filename.
BIAS_ProjParaPersp_DISTORTION_TYPE
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
void SetTime(unsigned long long int sec, unsigned long long int usec)
Set time and ensure correct format (seconds and useconds after 'sec')
void CreatePerspective(const BIAS::Pose &pose, const BIAS::KMatrix &K, int width, int height, BIAS_ProjParaPersp_DISTORTION_TYPE radDistType=DISTYPE_DEF, const std::vector< double > &UndistortionCoefficients=std::vector< double >(4, 0.0))
Create a perspective camera and add to projection.
static Pose PoseFromMeta(const PMDImageMetaData &MetaData)
static KMatrix KFromMeta(const PMDImageMetaData &MetaData)
static UUID GenerateUUID(const bool &consecutively=DEFAULT_UUID_CONSECUTIVELY)
static function which simply produces a uuid and returns
This class simulates a video device by loading images from disk.