2023-05-29 23:05:56 +08:00

53 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 知识点改写框架api调用
框架目录结构
![属性文本](./img/1.png)
main.py api启动文件
from flask import Flask, request, jsonify
from detect import YOLOv5
from utils.general import cv2
import numpy as np
import base64
app = Flask(__name__)
yolov_5 = YOLOv5()
@app.route("/", methods=["POST"])
def index():
images = request.values.get("images")
input_image = base64.b64decode(images)
imBytes = np.frombuffer(input_image, np.uint8)
iImage = cv2.imdecode(imBytes, cv2.IMREAD_COLOR)
result = yolov_5.infer(iImage)
result = result[0].view(-1).int()
res_dict = {'coordinate': result.tolist()}
print(res_dict)
return jsonify(res_dict)
if __name__ == '__main__':
app.run(
host='127.0.0.1',
port=8888,
debug=True
)
test.py 测试文件
import base64
import requests
with open('16329967796715117.jpg', 'rb') as f:
image = base64.b64encode(f.read())
data = {
'images': image
}
response = requests.post('http://127.0.0.1:8888/', data=data)
print(response.json())