-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
142 lines (114 loc) · 3.42 KB
/
main.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Copyright (C) Lyq root#lyq.me
* File Name : main.cpp
* Creation Time : 2015-3-19
* Environment : Windows8.1-64bit VS2013 OpenCV2.4.9
* Homepage : http://www.lyq.me
*/
#include "baseFunction.h"
#include "io.h"
#include "buildGraph.h"
#include "surfaceCarving.h"
#include "pixelTag.h"
#include "pixelEnergy.h"
#include "compareWork.h"
#include "buildPyramid.h"
#include "resizeVideo.h"
#include "timeCompress.h"
#include "shotCut.h"
int main( void ) {
help();
// func type
int funcType = 2;
int videoId = 2;
int firstFrameId = 6404;
// paramater
bool enableUser = false;
int threadsNum = 8;
int blockSize = 16;
int layerLimit = 3;
int widthDeletedDefault = 70;
int colorDiffThred = 5;
int elePerTagThred = 300;
int bandWidthDefault = 50;
double keyFrameNumLimit = 0.5;
int badCutLimit = (int)(0.08 * widthDeletedDefault);
vector<int> shotArr;
switch ( funcType ) {
case 0:{
bool state;
state = video2Frames( videoId );
if ( !state ) return -2;
// shot Cut
cout << " Shot Cut --ING" << endl;
segShotCut( shotArr );
cout << " Convert Process Finished !! " << endl;
}
case 1:{
int globalTime = clock();
getShotCut( shotArr );
// resize shot
for ( int shotId = 1; shotId < (int)shotArr.size(); shotId++ ) {
if ( shotArr[shotId] <= firstFrameId ) continue;
int frameStId = shotArr[shotId - 1];
int frameEdId = shotArr[shotId];
cout << " Process Shot From " << frameStId << " To " << frameEdId << " --ING" << endl << endl;
int clock1 = clock();
// read frames
vector<Mat> frames;
bool state = readFrameStream( frameStId, frameEdId, frames );
if ( !state ) return -2;
// calculate Energy
vector<Mat> pixelEnergy;
vector<int> pixelTag;
int tagNum;
calcPixelTag( frames, pixelTag, tagNum, colorDiffThred, elePerTagThred, frameStId );
calcPixelEnergy( frames, pixelTag, tagNum, pixelEnergy, frameStId, enableUser );
// temporal compress
vector<int> keyFrame;
timeCompress( pixelEnergy, keyFrame, keyFrameNumLimit );
preserveKeyData( keyFrame, frames, pixelEnergy );
// resize Video
int widthDeleted = widthDeletedDefault;
vector<Mat> edgeProtect;
for ( int c = 0; c < 2; c++ ) {
if ( widthDeleted > 0 ) {
calcEdgeProtect( frames, edgeProtect );
//for ( int i = 0; i < keyFrame.size(); i++ ) cout << keyFrame[i] << endl;
clock2 = clock();
//cout << "2-1 " << clock2 - clock1 << endl;
resizeVideo( keyFrame, frames, pixelEnergy, edgeProtect, layerLimit, widthDeleted,
bandWidthDefault, badCutLimit, frameStId, frameEdId, threadsNum, blockSize, c );
int clock8 = clock();
cout << "8-2 " <<clock8 - clock2 << endl;
scaleVideo( keyFrame, frames, pixelEnergy, widthDeleted, frameStId, frameEdId, c );
rotateVideo( keyFrame, frames, pixelEnergy, frameStId, frameEdId, c );
} else {
copyFrame( frameStId, frameEdId );
}
}
cout << endl;
}
// finished
cout << " Shot Finished !! Well done !!" << endl;
globalTime = clock() - globalTime;
globalTime = (globalTime + 500) / 1000;
printf( " Global Time Used : %d min %d sec\n", globalTime / 60, globalTime % 60 );
//system( "pause" );
}
case 2:{
// write frame stream
writeFrameStream();
}
case 3:{
// write video
bool state = writeVideo( videoId );
if ( !state ) return -2;
break;
}
default:
break;
}
system( "pause" );
return 0;
}