-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathDepthCompressionTest.cpp
122 lines (107 loc) · 4.31 KB
/
DepthCompressionTest.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/***********************************************************************
DepthCompressionTest - Utility to check the results of compressing a
depth frame file.
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 <Misc/Timer.h>
#include <IO/File.h>
#include <IO/OpenFile.h>
#include <Kinect/FrameBuffer.h>
#include <Kinect/DepthFrameWriter.h>
#include <Kinect/DepthFrameReader.h>
int main(int argc,char* argv[])
{
/* Open the uncompressed depth stream file: */
IO::FilePtr depthFrameFile(IO::openFile("/work/okreylos/3DVideo/Kinect/DepthFrames.dat"));
depthFrameFile->setEndianness(Misc::LittleEndian);
/* Read the file header: */
unsigned int size[2];
depthFrameFile->read(size,2);
/* Create a background frame: */
unsigned short* backgroundFrame=new unsigned short[size[1]*size[0]];
unsigned short* bfPtr=backgroundFrame;
for(unsigned int y=0;y<size[1];++y)
for(unsigned int x=0;x<size[0];++x,++bfPtr)
*bfPtr=0x07ffU;
unsigned int numCaptureFrames=150;
/* Create the depth frame writer and reader: */
IO::FilePtr compressedDepthFrameFile(IO::openFile("/work/okreylos/3DVideo/Kinect/CompressedDepthFrames.dat",IO::File::ReadWrite));
Kinect::DepthFrameWriter depthFrameWriter(*compressedDepthFrameFile,size);
compressedDepthFrameFile->flush();
Kinect::DepthFrameReader depthFrameReader(*compressedDepthFrameFile);
/* Process all frames from the two depth frame files: */
double totalTime=0.0;
double maxTime=0.0;
unsigned int numFrames=0;
while(!depthFrameFile->eof())
{
/* Read the next uncompressed depth frame: */
Kinect::FrameBuffer frame0(size[0],size[1],size[1]*size[0]*sizeof(unsigned short));
frame0.timeStamp=depthFrameFile->read<double>();
unsigned short* frameBuffer0=frame0.getData<unsigned short>();
depthFrameFile->read(frameBuffer0,size[1]*size[0]);
if(numCaptureFrames>0)
{
/* Add the depth frame to the background frame: */
unsigned short* bfPtr=backgroundFrame;
const unsigned short* dfPtr=frameBuffer0;
for(unsigned int y=0;y<size[1];++y)
for(unsigned int x=0;x<size[0];++x,++bfPtr,++dfPtr)
if(*bfPtr>*dfPtr-2)
*bfPtr=*dfPtr-2;
--numCaptureFrames;
}
else
{
/* Remove background from the depth frame: */
const unsigned short* bfPtr=backgroundFrame;
unsigned short* dfPtr=frameBuffer0;
for(unsigned int y=0;y<size[1];++y)
for(unsigned int x=0;x<size[0];++x,++bfPtr,++dfPtr)
if(*dfPtr>=*bfPtr)
*dfPtr=0x07ffU;
}
/* Write the compressed depth frame: */
depthFrameWriter.writeFrame(frame0);
compressedDepthFrameFile->flush();
/* Read the next compressed depth frame: */
Misc::Timer uncompressTime;
Kinect::FrameBuffer frame1=depthFrameReader.readNextFrame();
uncompressTime.elapse();
double time=uncompressTime.getTime();
totalTime+=time;
if(maxTime<time)
maxTime=time;
++numFrames;
/* Compare the two frames: */
unsigned int numPixels=size[0]*size[1];
const unsigned short* f0Ptr=frameBuffer0;
const unsigned short* f1Ptr=frame1.getData<unsigned short>();
while(numPixels>0)
{
if(*f0Ptr!=*f1Ptr)
std::cerr<<"Difference in frame "<<numFrames-1<<", "<<numPixels<<" pixels left"<<std::endl;
++f0Ptr;
++f1Ptr;
--numPixels;
}
}
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;
}