-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDsFilter.py
68 lines (53 loc) · 1.83 KB
/
DsFilter.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
56
57
58
59
60
61
62
63
64
65
66
67
68
s = 'C:\\Users\\H S\\PycharmProjects\\arabic_ocr\\r\\zaa'
d = 'C:\\Users\\H S\\PycharmProjects\\arabic_ocr\\res\\zaa'
import cv2
import numpy as np
import os
import glob
import re
numbers = re.compile(r'(\d+)')
def numericalSort(value):
parts = numbers.split(value)
parts[1::2] = map(int, parts[1::2])
return parts
def operation(src, dst, write):
imgs = []
for filename in sorted(glob.glob(os.path.join(dst, '*.png')), key=numericalSort):
#print(filename)
_imgs = cv2.imread(filename, 0)
imgs.append(_imgs)
pxCount = []
for x in imgs:
temp = np.count_nonzero(x != 255)
if temp not in pxCount:
pxCount.append(temp)
print(pxCount)
test = []
for filename in sorted(glob.glob(os.path.join(src, '*.png')), key=numericalSort):
#print(filename)
_imgs = cv2.imread(filename, 0)
test.append(_imgs)
results = []
px = []
coco = 0
for x in test:
count = np.count_nonzero(x != 255)
px.append(count)
threshold = 1
for i in range(-threshold, threshold):
if count + i in pxCount:
coco += 1
results.append(x)
break
print(px)
print(coco,'match were found')
i = 0
for x in results:
idx = len(glob.glob(os.path.join(write, '*.png')))
cv2.imwrite('%d.png' % idx, x)
i += 1
folders = ['alif', 'baa', 'taa', 'seh', 'jiim', 'haa', 'khaa', 'daal', 'zaal', 'raa', 'zeen', 'siin', 'shiin',
'saad', 'daad', 'tah', 'zaa', 'een', 'ghin', 'faa', 'qaaf', 'kaaf', 'laam', 'miim', 'noon', 'heh', 'waaw',
'laamalif','yaa2']
for x in folders:
operation(s+x, d+x, d+x)