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

Private GIT Repository
4c0c55547fe28023a364675a051c0ecca8fc8838
[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(10):
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 elapsed_time=0
25 for i in range(10):
26     t = time.process_time()
27     im2=im.resize((256, 256))
28     im2.save("lena3.jpg",quality=quality)
29     elapsed_time += time.process_time() - t
30
31 print("time resize + pil",elapsed_time)
32
33 """
34
35
36 img = cv2.imread('lena.jpg')
37 elapsed_time=0
38
39
40 for i in range(100):
41     t = time.process_time()
42     cv2.imwrite("lena4.jpg", img,[int(cv2.IMWRITE_JPEG_QUALITY), quality])
43     elapsed_time += time.process_time() - t
44
45 print("time cv2",elapsed_time)
46
47
48 elapsed_time=0
49 for i in range(100):
50     t = time.process_time()
51     resized = cv2.resize(img, (256,256), interpolation=cv2.INTER_LINEAR)
52     cv2.imwrite("lena5.jpg", resized,[int(cv2.IMWRITE_JPEG_QUALITY), quality])
53     elapsed_time += time.process_time() - t
54
55 print("time resize + cv2",elapsed_time)
56 """
57
58
59 elapsed_time=0
60 t = time.process_time()
61 for i in range(10):
62
63     proc=subprocess.Popen("scp lena2.jpg bilbo.iut-bm.univ-fcomte.fr:/tmp", shell=True)
64     proc.wait()
65     
66 elapsed_time += time.process_time() - t
67 print("ssh normal",elapsed_time)
68
69
70 elapsed_time=0
71 t = time.process_time()
72 for i in range(10):
73
74     proc=subprocess.Popen("scp lena3.jpg bilbo.iut-bm.univ-fcomte.fr:/tmp", shell=True)
75     proc.wait()
76
77 elapsed_time += time.process_time() - t
78 print("ssh reduce",elapsed_time)