]> AND Private Git Repository - Cipher_code.git/blob - measure_energy_iot/image_compression.py
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
new
[Cipher_code.git] / measure_energy_iot / image_compression.py
1 from PIL import Image
2 import time
3 import cv2
4 import subprocess
5
6 import sys
7
8 quality=int(sys.argv[1])
9 print("quality ",quality)
10
11 im=Image.open("lena.jpg")
12 elapsed_time=0
13
14 for i in range(100):
15     t = time.process_time()
16     im.save("lena2.jpg",quality=quality)
17     elapsed_time += time.process_time() - t
18
19 print("time pil",elapsed_time)
20
21
22
23
24
25 elapsed_time=0
26 for i in range(100):
27     t = time.process_time()
28     im2=im.resize((256, 256))
29     im2.save("lena3.jpg",quality=quality)
30     elapsed_time += time.process_time() - t
31
32 print("time resize + pil",elapsed_time)
33
34
35
36
37 img = cv2.imread('lena.jpg')
38 elapsed_time=0
39
40
41 for i in range(100):
42     t = time.process_time()
43     cv2.imwrite("lena4.jpg", img,[int(cv2.IMWRITE_JPEG_QUALITY), quality])
44     elapsed_time += time.process_time() - t
45
46 print("time cv2",elapsed_time)
47
48
49 elapsed_time=0
50 for i in range(100):
51     t = time.process_time()
52     resized = cv2.resize(img, (256,256), interpolation=cv2.INTER_LINEAR)
53     cv2.imwrite("lena5.jpg", resized,[int(cv2.IMWRITE_JPEG_QUALITY), quality])
54     elapsed_time += time.process_time() - t
55
56 print("time resize + cv2",elapsed_time)
57
58 elapsed_time=0
59 for i in range(10):
60     t = time.process_time()
61     proc=subprocess.Popen("scp lena4.jpg bilbo:/tmp", shell=True)
62     proc.wait()
63     elapsed_time += time.process_time() - t
64
65 print("ssh normal",elapsed_time)
66
67
68 elapsed_time=0
69 for i in range(10):
70     t = time.process_time()
71     proc=subprocess.Popen("scp lena5.jpg bilbo:/tmp", shell=True)
72     proc.wait()
73     elapsed_time += time.process_time() - t
74
75 print("ssh reduce",elapsed_time)