forked from Souravirus/docWriter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageSegmenter2.py
69 lines (66 loc) · 1.62 KB
/
imageSegmenter2.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
69
import matplotlib.pyplot as plt
import numpy
import pickle
from sklearn.externals import joblib
from PIL import Image
import cv2
from converter import imageprepare
from scipy import misc
from resizeimage import resizeimage
def cutImage(start, count, mini, maxi, idx):
img = misc.imread("Hello1.png")
s1= img[mini:maxi, start:count]
img = Image.fromarray(s1)
img.save("pic"+str(count)+".png")
mnist = imageprepare("pic"+str(count)+".png")
mimage=[mnist[(i)*28:(i+1)*28] for i in range(28)]
plt.subplot(3,3,idx+1)
plt.imshow(mimage, cmap = plt.cm.gray_r, interpolation="nearest")
cf = joblib.load("trainedCF.sav")
print(cf.predict([mnist]), end = "")
A = cv2.imread("Hello1.png", 0)
arr = numpy.asarray(A)
typearr = 0
start = 0
tCount = 0
mode = 0
breaking = 0
output = ""
mini = 0
maxi = 0
for column in arr.T:
count = 0
prev = 1
currmod = 0
n = 0
for i in column:
if i!=255 and prev == 1:
count += 1
prev = 0
if mini == 0:
mini = n
elif n < mini:
mini = n
elif i == 255 and prev == 0:
prev = 1
if maxi == 0:
maxi = n
elif n > maxi:
maxi =n
n+=1
if count == 0:
currmod = 0
else:
currmod = 1
if mode != currmod and mode == 0:
start = tCount
mode = currmod
elif mode != currmod and mode == 1:
cutImage(start, tCount, mini, maxi, breaking)
start = tCount
mode = currmod
maxi = 0
mini = 0
breaking+=1
tCount += 1
plt.show()