-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclassificateZi.py
55 lines (43 loc) · 1.42 KB
/
classificateZi.py
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
# !/usr/bin/python
# coding:utf-8
# 分類行書 隸書 楷書
import shutil, os
from PIL import Image
from cv2 import cv2
path = '/Users/wei-chilan/Documents/python/chooseZi/liuGongCyuan'
TargetFolder = '/Users/wei-chilan/Documents/python/chooseZi/liuGongCyuan/jpg'
list = os.listdir(path)
# for filename in list:
# if not any(s in filename for s in ("行書", "隸書", "楷書")):
# print(filename)
# SourceFolder = os.path.join(path , filename)
# shutil.move(SourceFolder, TargetFolder)
# num = 0
# for filename in list:
# if "jpg" in filename:
# num = num + 1
# SourceFolder = os.path.join(path , filename)
# shutil.move(SourceFolder, TargetFolder)
def detectaaa(filename):
import imageio
import numpy as np
def img_estim(img, thrshld):
is_light = np.mean(img) > thrshld
return 'light' if is_light else 'dark'
try:
f = imageio.imread(filename, as_gray=True)
if img_estim(f, 127) == 'dark':
print(filename)
if not os.path.exists(TargetFolder):
print('create dic')
os.mkdir(TargetFolder)
shutil.move(filename, TargetFolder)
except:
print('error:', filename)
pass
for filename in list:
SourceFolder = os.path.join(path , filename)
if os.path.isdir(SourceFolder):
# skip directories
continue
detectaaa(SourceFolder)