Update app.py
Browse files
app.py
CHANGED
|
@@ -198,8 +198,6 @@ def calculate_and_display_angles(image_path, return_angles=False):
|
|
| 198 |
|
| 199 |
# Get pose landmarks
|
| 200 |
results = pose.process(image_rgb)
|
| 201 |
-
|
| 202 |
-
return 'hi'
|
| 203 |
|
| 204 |
if results.pose_landmarks:
|
| 205 |
ang , locs = calculate_angles_landmarks(results.pose_landmarks)
|
|
@@ -216,8 +214,8 @@ def calculate_and_display_angles(image_path, return_angles=False):
|
|
| 216 |
# Display the angle values at corresponding locations
|
| 217 |
def overlay_angle(angle, location, color=(0, 255, 0)):
|
| 218 |
# Coordinates are normalized, scale them to the image size
|
| 219 |
-
x = int(location[0]
|
| 220 |
-
y = int(location[1]
|
| 221 |
|
| 222 |
cv2.putText(image, f'{angle:.2f}', (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.3, color, 1)
|
| 223 |
|
|
@@ -263,6 +261,7 @@ app = Flask(__name__)
|
|
| 263 |
def hello():
|
| 264 |
return "This is my python code Adew"
|
| 265 |
|
|
|
|
| 266 |
########################################
|
| 267 |
@app.route('/1', methods=['POST'])
|
| 268 |
def upload_file():
|
|
@@ -275,15 +274,21 @@ def upload_file():
|
|
| 275 |
# send file with angles on image or just angles
|
| 276 |
if file and allowed_file(file.filename):
|
| 277 |
try:
|
| 278 |
-
file.seek(0)
|
| 279 |
-
mime_type, _ = mimetypes.guess_type(file.filename)
|
| 280 |
|
| 281 |
f1 = calculate_and_display_angles(file)
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
except Exception as e:
|
| 289 |
return {"message": f"Error processing file: {str(e)}"}, 500
|
|
|
|
| 198 |
|
| 199 |
# Get pose landmarks
|
| 200 |
results = pose.process(image_rgb)
|
|
|
|
|
|
|
| 201 |
|
| 202 |
if results.pose_landmarks:
|
| 203 |
ang , locs = calculate_angles_landmarks(results.pose_landmarks)
|
|
|
|
| 214 |
# Display the angle values at corresponding locations
|
| 215 |
def overlay_angle(angle, location, color=(0, 255, 0)):
|
| 216 |
# Coordinates are normalized, scale them to the image size
|
| 217 |
+
x = int(location[0] * image.shape[1])
|
| 218 |
+
y = int(location[1] * image.shape[0])
|
| 219 |
|
| 220 |
cv2.putText(image, f'{angle:.2f}', (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.3, color, 1)
|
| 221 |
|
|
|
|
| 261 |
def hello():
|
| 262 |
return "This is my python code Adew"
|
| 263 |
|
| 264 |
+
from flask import Response
|
| 265 |
########################################
|
| 266 |
@app.route('/1', methods=['POST'])
|
| 267 |
def upload_file():
|
|
|
|
| 274 |
# send file with angles on image or just angles
|
| 275 |
if file and allowed_file(file.filename):
|
| 276 |
try:
|
| 277 |
+
# file.seek(0)
|
| 278 |
+
# mime_type, _ = mimetypes.guess_type(file.filename)
|
| 279 |
|
| 280 |
f1 = calculate_and_display_angles(file)
|
| 281 |
+
|
| 282 |
+
success, encoded_image = cv2.imencode('.jpg', f1)
|
| 283 |
+
if not success:
|
| 284 |
+
return "Image encoding failed", 500
|
| 285 |
+
|
| 286 |
+
return Response(encoded_image.tobytes(), mimetype='image/jpeg')
|
| 287 |
+
|
| 288 |
+
# return send_file(
|
| 289 |
+
# BytesIO(file.read()), mimetype=mime_type,
|
| 290 |
+
# as_attachment=False, download_name=file.filename
|
| 291 |
+
# )
|
| 292 |
|
| 293 |
except Exception as e:
|
| 294 |
return {"message": f"Error processing file: {str(e)}"}, 500
|