矫正扭曲和图片方向分类接口化
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import logging
|
||||
|
||||
import cv2
|
||||
import requests
|
||||
from tenacity import retry, stop_after_attempt, wait_random
|
||||
|
||||
@@ -8,13 +7,46 @@ from tenacity import retry, stop_after_attempt, wait_random
|
||||
@retry(stop=stop_after_attempt(3), wait=wait_random(1, 3), reraise=True,
|
||||
after=lambda x: logging.warning('获取文档区域失败!'))
|
||||
def request_book_areas(img_path):
|
||||
"""
|
||||
请求文档区域识别接口
|
||||
:param img_path: 待识别图片路径
|
||||
:return: 文档图片路径列表
|
||||
"""
|
||||
url = 'http://det_api:5000/det/books'
|
||||
response = requests.post(url, {'img_path': img_path})
|
||||
if response.status_code == 200:
|
||||
response_data = response.json()
|
||||
books = []
|
||||
for books_path in response_data:
|
||||
books.append(cv2.imread(books_path))
|
||||
return books
|
||||
return response.json()
|
||||
else:
|
||||
return []
|
||||
return [img_path]
|
||||
|
||||
|
||||
@retry(stop=stop_after_attempt(3), wait=wait_random(1, 3), reraise=True,
|
||||
after=lambda x: logging.warning('矫正扭曲图片失败!'))
|
||||
def request_dewarped_image(img_path):
|
||||
"""
|
||||
请求矫正图片接口
|
||||
:param img_path: 待矫正图片路径
|
||||
:return: 矫正后的图片路径
|
||||
"""
|
||||
url = 'http://det_api:5001/dewarp'
|
||||
response = requests.post(url, {'img_path': img_path})
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
return img_path
|
||||
|
||||
|
||||
@retry(stop=stop_after_attempt(3), wait=wait_random(1, 3), reraise=True,
|
||||
after=lambda x: logging.warning('获取图片方向失败!'))
|
||||
def request_image_orientation(img_path):
|
||||
"""
|
||||
请求图片方向分类接口
|
||||
:param img_path: 待分类图片路径
|
||||
:return: 最有可能的两个图片方向
|
||||
"""
|
||||
url = 'http://det_api:5002/clas/orientation'
|
||||
response = requests.post(url, {'img_path': img_path})
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
return ['0', '90']
|
||||
|
||||
Reference in New Issue
Block a user