5
5
import pickle
6
6
import os
7
7
import shutil
8
- from zipfile import ZipFile
9
-
10
- def zipdir (path , ziph ): #creates zip file
11
- # ziph is zipfile handle
12
- for root , dirs , files in os .walk (path ):
13
- for file in files :
14
- ziph .write (os .path .join (root , file ))
15
8
16
9
def plot (x , y , name , ylabel = "residualMetric" ): # plot metric on graph
17
10
assert len (x ) == len (y )
@@ -21,7 +14,7 @@ def plot(x, y, name, ylabel="residualMetric"): # plot metric on graph
21
14
ax .plot (x , y , label = f'$x = Frame, $y = { ylabel } ' )
22
15
plt .title (name )
23
16
ax .legend ()
24
- fig .savefig (f'PLOT2 /{ name } _plot.png' )
17
+ fig .savefig (f'PLOT /{ name } _plot.png' )
25
18
26
19
def graphSession (filepath , pframeSet = 300 , countMax = 1000 , skip = 0 , process = ["residualMetric" ], meanMetricSize = 10 ): # create graph of mean compounded residualMetric
27
20
"""
@@ -30,23 +23,17 @@ def graphSession(filepath, pframeSet=300, countMax = 1000, skip=0, process=["res
30
23
pframeSet: number of predicted frames every i-frame
31
24
countMax: number of data points on the graphs
32
25
skip: how many frames to skip per frame
33
- process: 3 Parts, process 1 = residualMetric, process 2 = sizeMetric, process 3 = meanMetric
26
+ process: 3 Parts, process 1 = residualMetric, process 2 = meanMetric
34
27
Process 1: create graph of residualMetric per I-Frame interval
35
-
36
- Process 2: Graph the data size of zip file containing the I-Frame and Residual Frame to
37
- analyze data savings across a video.
38
-
39
- Process 3: create graph of mean compounded residualMetric for x Frames specified by meanMetricSize
28
+ Process 2: create graph of mean compounded residualMetric for x Frames specified by meanMetricSize
40
29
"""
41
- assert "residualMetric" in process or "sizeMetric" in process or " meanMetric" in process
30
+ assert "residualMetric" in process or "meanMetric" in process
42
31
43
32
video_name , video , frame_width , frame_height , videofps , videoframecount = read_video (filepath )
44
- print (f"FPS: { videofps } " )
45
33
running = True
46
34
count = 0
47
35
48
36
residualTally = []
49
- sizeTally = []
50
37
meanTally = []
51
38
meanBuffer = []
52
39
@@ -63,32 +50,12 @@ def graphSession(filepath, pframeSet=300, countMax = 1000, skip=0, process=["res
63
50
if "residualMetric" in process :
64
51
residualTally .append (residualMetric )
65
52
66
- if "sizeMetric" in process :
67
-
68
- if os .path .exists ('sizeBuffer' ):
69
- shutil .rmtree ("sizeBuffer" )
70
- os .mkdir ('sizeBuffer' )
71
-
72
- cv2 .imwrite (os .path .join ("sizeBuffer" , 'iframe.png' ), iframe )
73
- cv2 .imwrite (os .path .join ("sizeBuffer" , 'residual.png' ), residualFrame )
74
-
75
- if os .path .exists ('sizeBuffer.zip' ):
76
- os .remove ("sizeBuffer.zip" )
77
-
78
- zipObj = ZipFile ('sizeBuffer.zip' , 'w' ) # create a ZipFile object
79
- zipObj .write (os .path .join ("sizeBuffer" , 'iframe.png' )) # Add multiple files to the zip
80
- zipObj .write (os .path .join ("sizeBuffer" , 'residual.png' ))
81
- zipObj .close () # close the Zip File
82
-
83
- sizeTally .append (os .path .getsize ('sizeBuffer.zip' ))
84
-
85
53
if "meanMetric" in process :
86
54
meanBuffer .append (residualMetric )
87
55
if len (meanBuffer ) == meanMetricSize :
88
56
meanTally .append (sum (meanBuffer )/ meanMetricSize )
89
57
meanBuffer .pop (0 )
90
58
91
-
92
59
running , frame = read_frame (video )
93
60
count += 1
94
61
@@ -99,70 +66,22 @@ def graphSession(filepath, pframeSet=300, countMax = 1000, skip=0, process=["res
99
66
if "residualMetric" in process :
100
67
plot (metricRange , residualTally , f"residual_{ video_name } _{ pframeSet } predF{ skip } skipF" , ylabel = "residualMetric" )
101
68
102
- if "sizeMetric" in process :
103
- plot (metricRange , sizeTally , f"size_{ video_name } _{ pframeSet } predF{ skip } skipF" , ylabel = " zipped [residualFrame, iFrame] Size" )
104
-
105
69
if "meanMetric" in process :
106
70
meanMetricRange = np .arange (len (meanTally ))
107
71
plot (meanMetricRange , meanTally , f"mean_{ video_name } _{ pframeSet } predF{ skip } skipF{ meanMetricSize } meanSize" , ylabel = f"{ meanMetricSize } Frame Mean Compounded residualMetric" )
108
72
109
- return residualTally , sizeTally , meanTally
110
-
111
- ### TESTS ####
112
-
113
- def test1 (): #analyze 4 examples
114
- imagePath = "testImages"
115
- outPath = "OUTPUT"
116
-
117
- setsToTest = [("personFrame1.png" , "personFrame2.png" , "personFrameOutput" ),
118
- ("personFrameLong1.png" , "personFrameLong2.png" , "personFrameLongOutput" ),
119
- ("carFrame1.png" , "carFrame2.png" , "carFrameOutput" ),
120
- ("carFrameLong1.png" , "carFrameLong2.png" , "carFrameLongOutput" )
121
- ]
122
-
123
- for pairs in setsToTest :
124
- anchorPath = f"{ imagePath } /{ pairs [0 ]} "
125
- targetPath = f"{ imagePath } /{ pairs [1 ]} "
126
-
127
- print ("Pair" , pairs )
128
- timer = time .time ()
129
-
130
- main (anchorPath , targetPath , f"{ outPath } /{ pairs [2 ]} " , saveOutput = True )
131
- totTime = time .time () - timer
132
- print (f"Done, executed in { totTime :.2f} s\n " )
133
-
134
- def test2 (filepath , pframeSet = 300 , countMax = 1000 , skip = 0 , process = ["residualMetric" ]): # create graph of residualMetric per I-Frame interval
135
- return graphSession (filepath , pframeSet , countMax , skip , process )
136
-
137
- def test3 (filepath , pframeSet = 300 , countMax = 1000 , skip = 0 , process = ["pickleMetric" ]): # create graph of residualMetric + I-frame size
138
- return graphSession (filepath , pframeSet , countMax , skip , process )
139
-
140
- def test4 (filepath , pframeSet = 300 , countMax = 1000 , skip = 0 , process = ["meanMetric" ]): # create graph of residualMetric + I-frame size
141
- return graphSession (filepath , pframeSet , countMax , skip , process )
142
-
143
- ### TESTS ####
73
+ return residualTally , meanTally
144
74
145
75
if __name__ == "__main__" :
146
76
timer = time .time ()
147
77
148
78
"""
149
- videopathA = "/Users/gbanuru/PycharmProjects/BlockMatching/VIDEOS/UAV123_person1_resized360.mp4"
150
- videopathB = "/Users/gbanuru/PycharmProjects/BlockMatching/VIDEOS/UAV123_car2_resized360.mp4"
151
- videopathC = "/Users/gbanuru/PycharmProjects/BlockMatching/VIDEOS/CityWalk_resized360.mp4"
152
- videopathD = "/Users/gbanuru/PycharmProjects/BlockMatching/VIDEOS/HouseTour_resized360.mp4"
153
-
79
+ videopathA = "VIDEOS/UAV123_person1_resized360.mp4"
154
80
PROCESS = ["meanMetric"]
155
-
156
81
graphSession(videopathA, pframeSet=5, process=PROCESS, meanMetricSize=5)
157
- graphSession(videopathB, pframeSet=5, process=PROCESS, meanMetricSize=5)
158
- graphSession(videopathC, pframeSet=5, process=PROCESS, meanMetricSize=5)
159
- graphSession(videopathD, pframeSet=5, process=PROCESS, meanMetricSize=5)
160
-
161
82
graphSession(videopathA, pframeSet=10, process=PROCESS, meanMetricSize=10)
162
- graphSession(videopathB, pframeSet=10, process=PROCESS, meanMetricSize=10)
163
- graphSession(videopathC, pframeSet=10, process=PROCESS, meanMetricSize=10)
164
- graphSession(videopathD, pframeSet=10, process=PROCESS, meanMetricSize=10)
83
+
165
84
"""
166
85
167
86
totTime = time .time () - timer
168
- print (f"Done, executed in { totTime :.2f} s" )
87
+ print (f"Done, executed in { totTime :.2f} s" )
0 commit comments