update

parent 2e8b7b6d
import cv2
import flask
import torch
import werkzeug
app = flask.Flask(__name__)
model = torch.hub.load('ultralytics/yolov5', 'custom', path='model/best.pt')
@app.route('/test', methods=['GET', 'POST'])
def test():
img = cv2.imread('upload/2012-12-15_08_10_03_jpg.rf.79ed952a7195142a1e08028ac5938d1a.jpg')
results = model(img)
return results.pandas().xyxy[0].to_json(orient='records')
@app.route('/upload', methods=['POST'])
def upload():
imagefile = flask.request.files['image']
filename = werkzeug.utils.secure_filename(imagefile.filename)
print("\nReceived image File name : " + imagefile.filename)
imagefile.save('Upload/' + filename)
img = cv2.imread('Upload/' + filename)
results = model(img)
return results.pandas().xyxy[0].to_json(orient='records')
@app.route('/cctv', methods=['GET', 'POST'])
def cctv():
cam = cv2.VideoCapture(0)
img = cam.read()[1]
cv2.imwrite('Cctv/snap.jpg', img)
results = model(img)
return results.pandas().xyxy[0].to_json(orient='records')
app.run(host="0.0.0.0", port=5000, debug=True)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment