34 lines
893 B
Python
34 lines
893 B
Python
import os.path
|
|
|
|
import cv2
|
|
from flask import Flask, request, Blueprint
|
|
|
|
from paddle_detection import detector
|
|
from util.common_util import process_request
|
|
|
|
app = Flask(__name__)
|
|
det_bp = Blueprint('det_bp', __name__)
|
|
app.register_blueprint(det_bp, url_prefix='/det')
|
|
|
|
|
|
@det_bp.route('/books', methods=['POST'])
|
|
@process_request
|
|
def books():
|
|
img_path = request.form['img_path']
|
|
image = cv2.imread(img_path)
|
|
result = detector.get_book_areas(image)
|
|
|
|
dirname = os.path.dirname(img_path)
|
|
img_name, ext = os.path.basename(img_path).rsplit('.', 1)
|
|
books_path = []
|
|
for i in range(len(result)):
|
|
save_path = os.path.join(dirname, img_name + '_book_' + str(i) + '.' + ext)
|
|
with open(save_path, 'wb') as file:
|
|
file.write(result[i])
|
|
books_path.append(save_path)
|
|
return books_path
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run('0.0.0.0', 5000)
|