@@ -40,23 +40,16 @@ def line_array(array):
40
40
41
41
grey_img = cv2 .cvtColor (src_img , cv2 .COLOR_BGR2GRAY )
42
42
43
- # gud_img = cv2.adaptiveThreshold(grey_img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY_INV,1001,2)
44
- gud_img = cv2 .adaptiveThreshold (grey_img ,255 ,cv2 .ADAPTIVE_THRESH_GAUSSIAN_C ,cv2 .THRESH_BINARY_INV ,1001 ,2 )
43
+ gud_img = cv2 .adaptiveThreshold (grey_img ,255 ,cv2 .ADAPTIVE_THRESH_MEAN_C ,cv2 .THRESH_BINARY_INV ,101 ,2 )
45
44
46
45
kernel = cv2 .getStructuringElement (cv2 .MORPH_ELLIPSE ,(3 ,3 ))
47
46
noise_remove = cv2 .erode (gud_img ,kernel ,iterations = 2 )
48
47
49
-
50
- # kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3))
51
48
kernel1 = np .array ([[1 ,0 ,1 ],[0 ,1 ,0 ],[1 ,0 ,1 ]], dtype = np .uint8 )
52
- final_thr = cv2 .dilate (gud_img ,kernel1 ,iterations = 2 )
53
-
54
-
55
-
56
- # closing = cv2.morphologyEx(gud_img, cv2.MORPH_OPEN, kernel, iterations = 1) # To remove "pepper-noise"
57
- # final_thr = np.empty(final.shape, dtype=np.uint8)
58
- # cv2.bitwise_not(final1, final_thr)
59
49
50
+ opening = cv2 .morphologyEx (gud_img , cv2 .MORPH_OPEN , kernel , iterations = 2 ) # To remove "pepper-noise"
51
+ kernel1 = np .array ([[1 ,0 ,1 ],[0 ,1 ,0 ],[1 ,0 ,1 ]], dtype = np .uint8 )
52
+ final_thr = cv2 .dilate (noise_remove ,kernel1 ,iterations = 3 )
60
53
61
54
#-------------/Thresholding Image-------------#
62
55
@@ -71,14 +64,12 @@ def line_array(array):
71
64
# print(count_x[y])
72
65
73
66
line_list = line_array (count_x )
74
- print (line_list )
67
+ # print(line_list)
75
68
76
69
# t = np.arange(0,height, 1)
77
70
# plt.plot(t, count_x[t])
78
71
# plt.axis([0, height, 0, 350])
79
- # plt.show()
80
72
81
- # k = cv2.waitKey(0)
82
73
83
74
# for y in range(len(line_list)):
84
75
# if :
@@ -118,8 +109,9 @@ def line_array(array):
118
109
cv2 .drawContours (final_contr , contours , - 1 , (0 ,255 ,0 ), 3 )
119
110
120
111
for cnt in contours :
121
- x ,y ,w ,h = cv2 .boundingRect (cnt )
122
- cv2 .rectangle (src_img ,(x ,y ),(x + w ,y + h ),(0 ,255 ,0 ),2 )
112
+ if cv2 .contourArea (cnt ) > 100 :
113
+ x ,y ,w ,h = cv2 .boundingRect (cnt )
114
+ cv2 .rectangle (src_img ,(x ,y ),(x + w ,y + h ),(0 ,255 ,0 ),2 )
123
115
124
116
#-------------/Character segmenting-----------#
125
117
@@ -137,6 +129,8 @@ def line_array(array):
137
129
cv2 .imshow ("Threshold Image" , final_thr )
138
130
cv2 .imshow ("Contour Image" , final_contr )
139
131
132
+ # plt.show()
133
+
140
134
#-------------/Displaying Image---------------#
141
135
142
136
0 commit comments