0% found this document useful (0 votes)
6 views

Task

Uploaded by

mho150740
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Task

Uploaded by

mho150740
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

from flask import Flask, Response

import cv2
import mediapipe as mp

app = Flask(_name_)
cap = None

@app.route('/1')
def babinski_reflex():
global cap
# Initialize hand tracking
mp_hands = mp.solutions.hands
hands = mp_hands.Hands()
mp_drawing = mp.solutions.drawing_utils
mp_drawing_styles = mp.solutions.drawing_styles
mp_pose = mp.solutions.pose

# Check if the camera is already opened


if cap is None or not cap.isOpened():
# Open the camera
cap = cv2.VideoCapture(0) # Use 0 for the default camera

def generate_frames():
while cap.isOpened():
success, image = cap.read()
if not success:
print("Camera not accessible.")
break

# Convert the image to RGB and pass it to mediapipe


image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
results = hands.process(image_rgb)
flag = False

# add test for exit


cv2.putText(image, "Stroke the sole of the foot !"
, (400, 550), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 128), 2)
cv2.putText(image, "If the Babinski reflex is present, ", (400, 570),
cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 128),
2)
cv2.putText(image, "the big toe will move upward as the other toes fan
outward"
, (200, 590), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 128), 2)
cv2.putText(image, "Press q when finish", (50, 630),
cv2.FONT_HERSHEY_PLAIN, 1, (0, 0, 255), 2)

pre_distance = 0.1
# Check if a hand is detected
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
# Get the landmarks of the thumb and the big toe (foot)
thumb_tip =
hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_TIP]
big_toe = hand_landmarks.landmark[
mp_hands.HandLandmark.INDEX_FINGER_TIP] # Reusing index
finger tip landmark for the big toe

# Calculate the distance between the thumb and big toe


landmarks
distance = ((thumb_tip.x - big_toe.x) * 2 + (thumb_tip.y -
big_toe.y) * 2) ** 0.5

# Check if the distance is greater than a threshold (indicating


a positive Babinski reflex)
if distance > 0.1:
cv2.putText(image, "Positive Babinski reflex!", (50, 50),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255),
2)
flag = True
else:
cv2.putText(image, "No Babinski reflex observed", (50, 50),
cv2.FONT_HERSHEY_SIMPLEX, 1,
(0, 255, 0), 2)
for landmark in hand_landmarks.landmark:
x = int(landmark.x * image.shape[1])
y = int(landmark.y * image.shape[0])
cv2.circle(image, (x, y), 5, (0, 255, 0), -1)

# Convert the frame to a byte stream


ret, buffer = cv2.imencode('.jpg', image)
frame_bytes = buffer.tobytes()

# Yield the frame as byte stream


yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame_bytes + b'\r\n')

# Wait for a key press and check if 'q' is pressed to exit


if cv2.waitKey(1) & 0xFF == ord('q'):
break

return Response(generate_frames(), mimetype='multipart/x-mixed-replace;


boundary=frame')

if _name_ == '_main_':
app.run(host='0.0.0.0', port=53333)

import 'package:flutter/material.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mjpeg/flutter_mjpeg.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomeScreen(),
);
}
}

class HomeScreen extends StatelessWidget {


@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home'),
),
body: Center(
child: ElevatedButton(
child: Text('Open Live Camera'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CameraScreen()),
);
},
),
),
);
}
}

class CameraScreen extends StatelessWidget {


@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Camera Stream'),
),
body: Center(
child: Mjpeg(
isLive: true,
stream: 'http://10.0.0.14:55899/1',
),
),
);
}
}
10.0.0.14

You might also like