1 #include "VideoStream.hh"
10 #include <Base/Image/ImageIO.hh>
13 VideoStream::~VideoStream() {}
16 VideoStream::VideoStream()
22 VideoStream::VideoStream(
const std::string & file)
41 BIASERR(
"Assignment operator is not correct due to missing fstream assignment! (jw)");
53 int VideoStream::Open(
const std::string & file)
55 Ifs_.open(file.c_str(),ios::binary);
57 BIASERR(
"Can not open file for reading");
61 Ifs_.seekg(0,ios_base::end);
62 FileSize_ = (
unsigned long) Ifs_.tellg();
63 Ifs_.seekg(0,ios_base::beg);
64 Ifs_.read(reinterpret_cast<char *>(&Header_),
sizeof(Header_));
66 BIASERR(
"error reading from file");
71 ImageSize_ = Header_.Width * Header_.Height * Header_.ChannelCount
72 * Header_.BytesPerPixel;
74 NumImages_ = (FileSize_ -
sizeof(Header_)) / Header_.AlignedSize;
80 int VideoStream::Close()
87 int VideoStream::SplitIntoFiles(
const std::string &prefix,
unsigned int start,
91 BIASERR(
"VideoStream not open.");
96 unsigned int numimages;
97 ostringstream filename;
99 unsigned int paddingsize = Header_.AlignedSize - ImageSize_-
sizeof(imghead);
100 cout <<
"Paddingsize: "<<paddingsize<<endl;
103 img.
Init(Header_.Width, Header_.Height, Header_.ChannelCount);
104 char *imgdata =
reinterpret_cast<char *
> (img.
GetImageData());
105 if (count ==0) numimages = NumImages_ ;
106 else numimages = count + start;
107 for (
unsigned int i=start;i<numimages; i++) {
108 Ifs_.read(reinterpret_cast<char *>(&imghead),
sizeof(imghead));
109 if (!Ifs_)
return -1;
110 Ifs_.read(imgdata, ImageSize_);
111 if (!Ifs_)
return -1;
116 cout <<
"file: "<<filename.str()<<
" UUID: "<<img.
GetUID()<<
" Time: "
117 <<imghead.
tsec<<
" "<<imghead.
tusec<<endl;
120 ImageIO::Save(filename.str(),
124 BIAS_DEFAULT_IMAGE_QUALITY,
126 Ifs_.seekg(paddingsize,ios_base::cur);
134 void VideoStream::PrintHeader()
137 cout <<
"FileSize: "<<FileSize_<<endl;
138 cout <<
"Image width, height, channelcout, BpP: "<<Header_.Width<<
"x"
139 <<Header_.Height<<
", "<<(int)Header_.ChannelCount<<
", "
140 <<(
int)Header_.BytesPerPixel<<endl;
142 cout <<
"StorageType, ColorModel: "
143 <<int(Header_.StorageType)<<
", "
144 <<int(Header_.ColorModel)<<endl;
146 cout <<
"ImageSize, BlockSize: "<<ImageSize_<<
", "<<Header_.AlignedSize<<endl;
147 cout <<
"NumImages: "<<NumImages_<<endl;
148 cout <<
"Remainer: "<<FileSize_ -
sizeof(Header_) - NumImages_ *
149 Header_.AlignedSize<<endl;
const BIAS::UUID & GetUID() const
returns the UUID of the image
bool SetFromString(const std::string &sID)
construct from string containing ascii uuid.
To allow capturing of camera image to disk efficiently, (avoid multiple memcopy operations), this class defines an interface to file containing one header and multiple images.
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
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
void SetUID(const BIAS::UUID &id)
int UpdateMetaData()
copy P_ and co.
interface class for producing/storing Universally Unique IDentifiers
unsigned long int FileSize_