-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeed_testing.py
More file actions
140 lines (116 loc) · 3.73 KB
/
speed_testing.py
File metadata and controls
140 lines (116 loc) · 3.73 KB
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
# Python 2.7 code to test the speed of operation of
# different commands. This need arose when the speed
# of compressing and decompressing data came.
import zlib
import cv2
import numpy as np
import time
from cPickle import dumps, loads
# =========GRAY 640x480=========
print "=========GRAY 640x480========="
img = cv2.imread('capt_640_gray.png', 0)
'''
start = time.time()
img_d = dumps(img)
print "Dumping Time: ", (time.time()-start)
start = time.time()
img_d_c = zlib.compress(img_d, 1)
print "Compression Time: ", (time.time()-start)
'''
start = time.time()
img_cm = zlib.compress(img, 1)
print "Matrix Compression Time: ", (time.time()-start)
'''
start = time.time()
img_d_c_d = zlib.decompress(img_d_c)
print "Decompression Time: ", (time.time()-start)
print "Compression Ratio with Dumps: ", (len(img_d)/len(img_d_c))
print "Compression Ratio of Matrix: ", (len(img_d)/len(img_cm))
'''
print 'Length of Compressed Matrix String: ', len(img_cm)
img_cm_re = np.fromstring(zlib.decompress(img_cm), img.dtype)
img_cm_re = np.reshape(img_cm_re,(480,640))
cv2.imwrite('reconstruct_G640.png', img_cm_re)
print ""
print ""
# =========COLOR 640x480=========
print "=========COLOR 640x480========="
img = cv2.imread('capt_640_colo.png', 1)
'''
start = time.time()
img_d = dumps(img)
print "Dumping Time: ", (time.time()-start)
start = time.time()
img_d_c = zlib.compress(img_d, 1)
print "Compression Time: ", (time.time()-start)
'''
start = time.time()
img_cm = zlib.compress(img, 1)
print "Matrix Compression Time: ", (time.time()-start)
'''
start = time.time()
img_d_c_d = zlib.decompress(img_d_c)
print "Decompression Time: ", (time.time()-start)
print "Compression Ratio with Dumps: ", (len(img_d)/len(img_d_c))
print "Compression Ratio of Matrix: ", (len(img_d)/len(img_cm))
'''
print 'Length of Compressed Matrix String: ', len(img_cm)
img_cm_re = np.fromstring(zlib.decompress(img_cm), img.dtype)
img_cm_re = np.reshape(img_cm_re,(480,640,3))
cv2.imwrite('reconstruct_C640.png', img_cm_re)
print ""
print ""
# =========GRAY 320x240=========
print "=========GRAY 320x240========="
img = cv2.imread('capt_320_gray.png', 0)
'''
start = time.time()
img_d = dumps(img)
print "Dumping Time: ", (time.time()-start)
start = time.time()
img_d_c = zlib.compress(img_d, 1)
print "Compression Time: ", (time.time()-start)
'''
start = time.time()
img_cm = zlib.compress(img, 1)
print "Matrix Compression Time: ", (time.time()-start)
'''
start = time.time()
img_d_c_d = zlib.decompress(img_d_c)
print "Decompression Time: ", (time.time()-start)
print "Compression Ratio with Dumps: ", (len(img_d)/len(img_d_c))
print "Compression Ratio of Matrix: ", (len(img_d)/len(img_cm))
'''
print 'Length of Compressed Matrix String: ', len(img_cm)
img_cm_re = np.fromstring(zlib.decompress(img_cm), img.dtype)
img_cm_re = np.reshape(img_cm_re,(240, 320))
cv2.imwrite('reconstruct_G320.png', img_cm_re)
print ""
print ""
# =========COLOUR 320x240=========
print "=========COLOR 320x240========="
img = cv2.imread('capt_320_colo.png', 1)
'''
start = time.time()
img_d = dumps(img)
print "Dumping Time: ", (time.time()-start)
start = time.time()
img_d_c = zlib.compress(img_d, 1)
print "Compression Time: ", (time.time()-start)
'''
start = time.time()
img_cm = zlib.compress(img, 1)
print "Matrix Compression Time: ", (time.time()-start)
'''
start = time.time()
img_d_c_d = zlib.decompress(img_d_c)
print "Decompression Time: ", (time.time()-start)
print "Compression Ratio with Dumps: ", (len(img_d)/len(img_d_c))
print "Compression Ratio of Matrix: ", (len(img_d)/len(img_cm))
'''
print 'Length of Compressed Matrix String: ', len(img_cm)
img_cm_re = np.fromstring(zlib.decompress(img_cm), img.dtype)
img_cm_re = np.reshape(img_cm_re,(240, 320,3))
cv2.imwrite('reconstruct_C320.png', img_cm_re)
print ""
print ""