31 lines
749 B
Python
31 lines
749 B
Python
import os.path
|
|
|
|
import cv2
|
|
from flask import Flask, request
|
|
|
|
from paddle_detection import detector
|
|
from util import image_util
|
|
from util.common_util import process_request
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
@app.route('/det/books', methods=['POST'])
|
|
@process_request
|
|
def books():
|
|
img_path = request.form.get('img_path')
|
|
image = cv2.imread(img_path)
|
|
result = detector.get_book_areas(image)
|
|
|
|
dirname, img_name, ext = image_util.parse_path(img_path)
|
|
books_path = []
|
|
for i in range(len(result)):
|
|
save_path = os.path.join(dirname, img_name + '_book_' + str(i) + '.' + ext)
|
|
cv2.imwrite(save_path, result[i])
|
|
books_path.append(save_path)
|
|
return books_path
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run('0.0.0.0', 5000)
|