File size: 1,392 Bytes
6ae6f54
1ee215b
6ae6f54
 
b99602f
ebd4304
d97af08
6ae6f54
 
 
d97af08
ebd4304
 
6ae6f54
 
 
 
 
b99602f
6ae6f54
 
 
ebd4304
b99602f
6ae6f54
 
 
 
 
 
 
 
 
d97af08
6ae6f54
b99602f
 
 
6ae6f54
 
d97af08
6ae6f54
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from flask import Flask, request, jsonify
from PIL import Image
import io
import base64
import numpy as np
import logging

app = Flask(__name__)

# Dummy pose recognition function
def recognize_pose(image):
    # Replace this with your actual model inference code
    pose = "warrior"  # Dummy value for testing
    return pose

@app.route('/api/recognize_pose', methods=['POST'])
def api_recognize_pose():
    try:
        # Decode the image from the request
        image_data = request.json['image'].split(",")[1]
        image_bytes = base64.b64decode(image_data)
        image = Image.open(io.BytesIO(image_bytes))

        # Preprocess and recognize pose
        image = preprocess_image(image)
        pose = recognize_pose(image)
        return jsonify({'pose': pose})
    except KeyError as ke:
        logging.error(f"Key Error: {ke}")
        return jsonify({'error': 'Invalid input data format'}), 400
    except Exception as e:
        logging.error(f"Unexpected error: {e}")
        return jsonify({'error': str(e)}), 500

def preprocess_image(image):
    # Example preprocessing; adjust as needed for your model
    image = image.resize((224, 224))  # Resize image to expected input size
    image = np.array(image) / 255.0  # Normalize image
    image = np.expand_dims(image, axis=0)  # Add batch dimension
    return image

if __name__ == '__main__':
    app.run(debug=True)