, q1 + dw)
nm=(p2 - p1) * (q2 - q1)
u=0.0
x=[0] * 10
for i in range (p1, p2):
fl=0
for j in range (q1, q2):
y=nei [i] [j]
if y gt;=0:
x [y] +=1
if y == 0:
fl +=1
if fl == q2 - q1:
u +=1.0
if 0 in x [: 7] or nm gt; (x [3] + x [6]) * 20:
return x [9]
cnt1=x [3] * 16 + x [6] * 16
cnt2=x [0]
x [9]=int (cnt1 * cnt2 * 1.0/nm)
x [9]=int (x [9] * (1 + u/(p2 - p1)) ** 2)
if x [9] lt; 600 or x [9] gt; 3000:
x [9]=0
return x [9]
def get_text_regions ():
ww=w/dw
hh=h/dh
b=[[0] * (w + 3) for i in range (h + 1)]
for dy in (0, dh/2):
m=[[0] * (ww + 3) for i in range (hh + 1)]
for i in range (1 + dy, h, dh):
for j in range (1, w, dw):
m [(i - 1 - dy)/dh] [(j - 1)/dw]=stroke_calc (i, j)
for i in range (hh + 1):
for j in range (ww):
if m [i] [j]!=0 and m [i] [j + 1]!=0 and m [i] [j + 2]!=0 and
m [i] [j] + m [i] [j + 1] + m [i] [j + 2] gt; 3 * 800:
m [i] [ww + 2]=1
break
for i in range (hh + 1):
if m [i] [ww + 2] == 0:
continue
for j in range (ww + 1):
if m [i] [j]!=0:
h1=i * dh + 1 + dy
h2=h1 + dh
h2=min (h - 1, h2)
w1=j * dw + 1
w2=w1 + dw
w2=min (w - 1, w2)
for p in range (h1, h2):
b [p] [w + 2]=1
for q in range (w1, w2):
if nei [p] [q]!=0:
b [p] [q]=1
step=60
for i in range (h):
if b [i] [w + 2]!=0:
j=0
cnt=0
while j lt;=w - step:
if b [i] [j]!=0 and b [i] [j + 1]!=0 and b [i] [j + 2]!=0:
sm=sum (b [i] [j: j + step])
if sm gt; step * 0.4:
for k in range (j, j + step):
b [i] [k] +=2
cnt +=1
j +=step
else:
j +=1
else:
j +=1
if cnt == 0:
b [i]=[0] * (w + 3)
else:
b [i] [w + 2]=cnt
cnt=0
for i in range (h + 1):
if b [i] [w + 2] == 0:
if cnt gt; 0 and cnt lt; 8:
for ii in range (i - cnt, i):
b [ii]=[0] * (w + 3)
cnt=0
else:
cnt +=1
r=[]
for i in range (h):
for j in range (w):
if b [i] [j] gt; 1:
cnt=1
x1=w
x2=0
y1=h
y2=0
b [i] [j] *=- 1
v=[[i, j]]
while len (v)!=0:
ww=[]
for vv in v:
for k in range (8):
yy=vv [0] + d8 [k] [0]
xx=vv [1] + d8 [k] [1]
if xx lt; 0 or xx gt;=w or yy lt; 0 or yy gt;=h:
continue
if b [yy] [xx] gt; 1:
b [yy] [xx] *=- 1
ww +=[[yy, xx]]
x1=min (x1, xx)
x2=max (x2, xx)
y1=min (y1, yy)
y2=max (y2, yy)
v=ww [:]
cnt +=len (v)