38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
|
import json
|
||
|
import uuid
|
||
|
import websocket
|
||
|
from flask import Flask, request, jsonify
|
||
|
import sys
|
||
|
import openpose_gen as opg
|
||
|
|
||
|
sys.path.append('./')
|
||
|
|
||
|
app = Flask(__name__)
|
||
|
|
||
|
@app.route('/coordinates', methods=['POST'])
|
||
|
def receive_coordinates():
|
||
|
if request.is_json:
|
||
|
data = request.get_json()
|
||
|
coordinates = data['coordinates']
|
||
|
canvas_size = data['canvas_size']
|
||
|
|
||
|
if not coordinates or not canvas_size:
|
||
|
return jsonify({"status": "error", "message": "Missing data"}), 422
|
||
|
|
||
|
opg.save_bodypose(canvas_size, canvas_size, coordinates)
|
||
|
|
||
|
return jsonify({"status": "success", "message": "Data received"}), 201
|
||
|
else:
|
||
|
return jsonify({"status": "error", "message": "Request must be JSON"}), 415
|
||
|
|
||
|
def open_websocket_connection():
|
||
|
server_address='127.0.0.1:8188'
|
||
|
client_id=str(uuid.uuid4())
|
||
|
ws = websocket.WebSocket()
|
||
|
ws.connect("ws://{}/ws?clientId={}".format(server_address, client_id))
|
||
|
return ws, server_address, client_id
|
||
|
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
app.run(debug=True)
|