def
huakuiajuli(a,b):
a_img
=
cv2.imdecode(np.frombuffer(a,np.uint8),cv2.IMREAD_GRAYSCALE)
b_img
=
cv2.imdecode(np.frombuffer(b,np.uint8),cv2.IMREAD_GRAYSCALE)
yy
=
[]
xx
=
[]
for
y
in
range
(b_img.shape[
0
]):
for
x
in
range
(b_img.shape[
1
]):
r
=
b_img[y,x]
if
r<
200
:
yy.append(y)
xx.append(x)
b_img
=
b_img[
min
(yy):
max
(yy),
min
(xx):
max
(xx)]
a_edge
=
cv2.Canny(a_img,
100
,
200
)
b_edge
=
cv2.Canny(b_img,
100
,
200
)
a_pic
=
cv2.cvtColor(a_edge,cv2.COLOR_GRAY2RGB)
b_pic
=
cv2.cvtColor(b_edge,cv2.COLOR_GRAY2RGB)
res
=
cv2.matchTemplate(a_pic,b_pic,cv2.TM_CCOEFF_NORMED)
min_val,max_val,min_loc,max_loc
=
cv2.minMaxLoc(res)
th,tw
=
b_pic.shape[:
2
]
tl
=
max_loc
br
=
(tl[
0
]
+
tw,tl[
1
]
+
th)
cv2.rectangle(a_img,tl,br,(
0
,
0
,
255
),
2
)
cv2.imwrite(
"ditu01.png"
,a_img)
return
max_loc[
0
]