-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete4_multproc.py
More file actions
executable file
·67 lines (59 loc) · 1.53 KB
/
delete4_multproc.py
File metadata and controls
executable file
·67 lines (59 loc) · 1.53 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
from multiprocessing import Process
import sys
import os
import imageio
import numpy as np
from PIL import Image
def main(file):
print("start dealng files")
filename = file
print(filename)
try:
im = Image.open(filename)
im.verify() #I perform also verify, don't know if he sees other types o defects
im.close() #reload is necessary in my case
#Obselect
#im = Image.load(filename)
#im.transpose(PIL.Image.FLIP_LEFT_RIGHT)
#im.close()
#print("try 1 success")
except:
#manage excetions here
print("try 1 failed")
sys.exit(0)
#obselete
#f = imageio.imread(filename, as_gray=True)
try:
f = imageio.imread(filename, mode='L')
#print("Try 2 success")
#obselete
#try:
# imageio.verify(f)
# do stuff
except IOError:
# filename not an image file
print("IO error")
sys.exit(0)
def img_estim(img, thrshld):
is_light = np.mean(img) > thrshld
#print(np.mean(img))
#return 'light' if is_light else os.remove(filename)
if is_light == 0:
os.remove(filename)
img_estim(f, 40)
#print(img_estim(f, 40))
#print
if __name__ == '__main__':
p = Process(target=main, args=(sys.argv[-1],))
#print("start")
p.start()
#print("join process")
p.join()
# try:
# main()
# except KeyboardInterrupt:
# print('Interrupted')
# try:
# sys.exit(0)
# except SystemExit:
# os._exit(0)