32 lines
774 B
Python
32 lines
774 B
Python
import logging.config
|
|
import os.path
|
|
|
|
import cv2
|
|
from flask import Flask, request
|
|
|
|
from log import LOGGING_CONFIG
|
|
from paddle_detection import detector
|
|
from utils import process_request, parse_img_path
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
@app.route('/', methods=['POST'])
|
|
@process_request
|
|
def main():
|
|
img_path = request.form.get('img_path')
|
|
result = detector.get_book_areas(img_path)
|
|
|
|
dirname, img_name, img_ext = parse_img_path(img_path)
|
|
books_path = []
|
|
for i in range(len(result)):
|
|
save_path = os.path.join(dirname, f'{img_name}.book_{i}.{img_ext}')
|
|
cv2.imwrite(save_path, result[i])
|
|
books_path.append(save_path)
|
|
return books_path
|
|
|
|
|
|
if __name__ == '__main__':
|
|
logging.config.dictConfig(LOGGING_CONFIG)
|
|
app.run('0.0.0.0', 5006)
|