mirror of
https://github.com/tcsenpai/poser.git
synced 2025-06-06 19:25:23 +00:00
19 lines
486 B
Python
19 lines
486 B
Python
import cv2
|
|
import numpy as np
|
|
import tensorflow as tf
|
|
|
|
def preprocess_image(frame):
|
|
img = cv2.resize(frame, (224, 224))
|
|
img = img.astype('float32') / 255.0
|
|
img = np.expand_dims(img, axis=0)
|
|
return img
|
|
|
|
def detect_posture(frame, model):
|
|
preprocessed = preprocess_image(frame)
|
|
prediction = model(preprocessed, training=False)
|
|
prediction = tf.nn.softmax(prediction.logits)
|
|
|
|
if prediction[0][1] > 0.5:
|
|
return "Good"
|
|
else:
|
|
return "Bad" |