def predict():
response = requests.get(slide_captcha_url)
base64_image = response.json()['data']['dataUrl']
base64_image_without_head = base64_image.replace('data:image/png;base64,', '')
bytes_io = BytesIO(base64.b64decode(base64_image_without_head))
img = np.array(Image.open(bytes_io).convert('RGB'))
img_blur = cv2.GaussianBlur(img, (3, 3), 0)
img_gray = cv2.cvtColor(img_blur, cv2.COLOR_BGR2GRAY)
img_canny = cv2.Canny(img_gray, 100, 200)
operator = get_operator('shape.png')
(x, y), _ = best_match(img_canny, operator)
x = x + bias
print('the position of x is', x)
buffer = mark(img, x, y)
return {'value': x, 'image': base64.b64encode(buffer.getbuffer()).decode()}
评论列表
文章目录