-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
130 lines (100 loc) · 3.14 KB
/
Copy pathapp.py
File metadata and controls
130 lines (100 loc) · 3.14 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import time
from flask import Flask, render_template, Response, jsonify, request
import random
import cv2 as cv2
import mediapipe as mp
import math
import numpy
from views.sight import *
app = Flask(__name__)
# 电脑自带摄像头
@app.route("/")
def start():
return render_template("startlink.html")
@app.route("/index")
def index():
return render_template("index.html")
@app.route("/test2")
def test2():
return render_template("test2.html", rotation_angle=generate_rotation_angle, finger_director=get_direction)
@app.route('/video_feed0')
def video_feed0():
return Response(gen_frames0(), mimetype='multipart/x-mixed-replace; boundary=frame')
detector = detector_
@app.route('/api/angle', methods=['GET'])
def generate_rotation_angle():
rand = random.randint(1, 4)
data = {'rotation_angle': rand}
return jsonify(data)
@app.route('/api/number', methods=['GET', 'POST'])
def generate_number():
options = [5, 6, 8, 9]
print(request.json)
value = request.json.get('value')
while True:
# 从列表中随机选择一个元素
rand = random.choice(options)
# 检查选择的元素是否等于要排除的值
if rand != value:
break
data = {'rand': rand}
return jsonify(data)
@app.route('/api/mediapipedirection', methods=['GET'])
def get_direction():
direction = detector.findDirection() # 获得手的信息
if direction:
data = {'direction': direction}
return jsonify(data)
else:
data = {'direction': 0}
return jsonify(data)
@app.route('/api/mediapipedirection2', methods=['GET'])
def get_direction22():
x = get_direction2()
if x:
return x
else:
return jsonify({'direction': 0})
# error_count = 0
# pre_size = -1
# best_vision = -1
# @app.route('/api/return', methods=['POST', 'GET'])
# def estimate_vision():
# global pre_size
# global error_count
# global best_vision
# data_received = request.json
#
# current_size = data_received.get('distance')
# true_or_wrong = data_received.get('answer')
#
# if pre_size == -1:
# pre_size = current_size
#
# if error_count == 2:
# data = {'best_vision': best_vision, 'exit': 1}
# else:
# if current_size == pre_size:
# error_count += 1 if not true_or_wrong else 0
# data = {'best_vision': best_vision, 'exit': 0}
# else:
# pre_size = current_size
# pre_size_vision = (pre_size / 400) * 5.0
# best_vision = pre_size_vision if best_vision < pre_size_vision else best_vision
# data = {'best_vision': best_vision, 'exit': 0}
#
# return jsonify(data) # 使用jsonify函数返回JSON格式的Response对象
@app.route('/api/init', methods=['GET'])
def init():
detector.initialize_camera()
while 1:
E_size = detector.Distance() # 获得字号大小
if E_size is not None:
data = {'E_size': E_size}
return jsonify(data)
@app.route('/api/close', methods=['GET', 'POST'])
def close():
detector.release_camera()
return jsonify({'state':True})
if __name__ == '__main__':
app.run()