-
Notifications
You must be signed in to change notification settings - Fork 23
/
ColorCompressionTest.cpp
79 lines (67 loc) · 3.05 KB
/
ColorCompressionTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/***********************************************************************
ColorCompressionTest - Utility to experiment with methods to compress
color frame streams.
Copyright (c) 2010-2015 Oliver Kreylos
This file is part of the Kinect 3D Video Capture Project (Kinect).
The Kinect 3D Video Capture Project is free software; you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
The Kinect 3D Video Capture Project is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with the Kinect 3D Video Capture Project; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
***********************************************************************/
#include <iostream>
#include <IO/File.h>
#include <IO/OpenFile.h>
#include <Misc/Timer.h>
#include <Kinect/FrameBuffer.h>
#include <Kinect/ColorFrameWriter.h>
#include <Kinect/ColorFrameReader.h>
int main(int argc,char* argv[])
{
/* Open the uncompressed color stream file: */
IO::FilePtr colorFrameFile(IO::openFile("/work/okreylos/3DVideo/Kinect/ColorFrames.dat"));
colorFrameFile->setEndianness(Misc::LittleEndian);
/* Read the file header: */
unsigned int size[2];
colorFrameFile->read(size,2);
/* Create the color frame writer and reader: */
IO::FilePtr compressedColorFrameFile(IO::openFile("/work/okreylos/3DVideo/Kinect/CompressedColorFrames.dat",IO::File::ReadWrite));
Kinect::ColorFrameWriter colorFrameWriter(*compressedColorFrameFile,size);
compressedColorFrameFile->flush();
Kinect::ColorFrameReader colorFrameReader(*compressedColorFrameFile);
/* Process all frames from the two color frame files: */
double totalTime=0.0;
double maxTime=0.0;
unsigned int numFrames=0;
while(!colorFrameFile->eof())
{
/* Read the next uncompressed color frame: */
Kinect::FrameBuffer frame0(size[0],size[1],size[1]*size[0]*3*sizeof(unsigned char));
frame0.timeStamp=colorFrameFile->read<double>();
unsigned char* frameBuffer0=frame0.getData<unsigned char>();
colorFrameFile->read(frameBuffer0,size[1]*size[0]*3);
/* Write the compressed color frame: */
colorFrameWriter.writeFrame(frame0);
compressedColorFrameFile->flush();
/* Read the next compressed color frame: */
Misc::Timer uncompressTime;
Kinect::FrameBuffer frame1=colorFrameReader.readNextFrame();
uncompressTime.elapse();
double time=uncompressTime.getTime();
totalTime+=time;
if(maxTime<time)
maxTime=time;
++numFrames;
}
std::cout<<"Total decompression time: "<<totalTime*1000.0<<" ms, "<<numFrames<<" frames"<<std::endl;
std::cout<<"Maximum decompression time: "<<maxTime*1000.0<<" ms"<<std::endl;
std::cout<<"Decompression frame rate: "<<double(numFrames)/totalTime<<" Hz"<<std::endl;
return 0;
}