|
|
@ -86,15 +86,13 @@ def handle_video_frame(message): |
|
|
|
_, img_data = base64_str.split(",") |
|
|
|
img_data = base64.b64decode(img_data) |
|
|
|
# 将字节流转换为PIL图像对象 |
|
|
|
# 将字节数据转换为NumPy数组 |
|
|
|
# 将字节数据转换为NumPy数组 |
|
|
|
np_data = np.frombuffer(img_data, dtype=np.uint8) |
|
|
|
|
|
|
|
# 使用cv2.imdecode将数组解码为图像 |
|
|
|
image = cv2.imdecode(np_data, cv2.IMREAD_COLOR) |
|
|
|
checkVedioResult(message, image) |
|
|
|
socketio.emit( |
|
|
|
"teacherVideo" + message["userId"], message, to=adminSid |
|
|
|
) |
|
|
|
socketio.emit("teacherVideo" + message["userId"], message, to=adminSid) |
|
|
|
|
|
|
|
|
|
|
|
def checkVedioResult(message, image): |
|
|
@ -105,7 +103,7 @@ def checkVedioResult(message, image): |
|
|
|
global class_name |
|
|
|
global clients |
|
|
|
global adminSid |
|
|
|
det_results = det_model(image,conf=0.5, iou=0.25) |
|
|
|
det_results = det_model(image, conf=0.5, iou=0.25) |
|
|
|
type = "" |
|
|
|
for r in det_results: |
|
|
|
if len(r) == 0: |
|
|
@ -133,20 +131,14 @@ def checkVedioResult(message, image): |
|
|
|
for item in clients: |
|
|
|
if item["id"] == message["userId"]: |
|
|
|
sid = item["sid"] |
|
|
|
socketio.emit( |
|
|
|
"studentMsg" + message["userId"], message, to=sid |
|
|
|
) |
|
|
|
socketio.emit("studentMsg" + message["userId"], message, to=sid) |
|
|
|
# print(97444, type) |
|
|
|
zuobiItem = { |
|
|
|
"userId": message["userId"], |
|
|
|
"msg": message["data"], |
|
|
|
"type": type, |
|
|
|
"create_at": time.strftime( |
|
|
|
"%Y-%m-%d %H:%M:%S", time.localtime(time.time()) |
|
|
|
), |
|
|
|
"update_at": time.strftime( |
|
|
|
"%Y-%m-%d %H:%M:%S", time.localtime(time.time()) |
|
|
|
), |
|
|
|
"create_at": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())), |
|
|
|
"update_at": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())), |
|
|
|
"isExit": 1, |
|
|
|
} |
|
|
|
addzuobi(zuobiItem) |
|
|
@ -158,9 +150,7 @@ def handle_talk(message): |
|
|
|
global adminSid |
|
|
|
# print(f"Received video frame from {message['userId']}") |
|
|
|
message["type"] = "talk" |
|
|
|
socketio.emit( |
|
|
|
"teacherTalk" + message["userId"], message, to=adminSid |
|
|
|
) |
|
|
|
socketio.emit("teacherTalk" + message["userId"], message, to=adminSid) |
|
|
|
zuobiItem = { |
|
|
|
"userId": message["userId"], |
|
|
|
"msg": message["data"], |
|
|
@ -177,9 +167,7 @@ def handle_msg(message): |
|
|
|
# 说话实时传输给老师 |
|
|
|
global adminSid |
|
|
|
# print(f"Received video frame from {message['userId']}") |
|
|
|
socketio.emit( |
|
|
|
"teacherMsg" + message["userId"], message, to=adminSid |
|
|
|
) |
|
|
|
socketio.emit("teacherMsg" + message["userId"], message, to=adminSid) |
|
|
|
zuobiItem = { |
|
|
|
"userId": message["userId"], |
|
|
|
"msg": message["data"], |
|
|
@ -198,9 +186,7 @@ def handle_answer_msg(message): |
|
|
|
if item["id"] == message["userId"]: |
|
|
|
sid = item["sid"] |
|
|
|
message["type"] = "answer" |
|
|
|
socketio.emit( |
|
|
|
"studentMsg" + message["userId"], message, to=sid |
|
|
|
) |
|
|
|
socketio.emit("studentMsg" + message["userId"], message, to=sid) |
|
|
|
zuobiItem = { |
|
|
|
"userId": message["userId"], |
|
|
|
"msg": message["data"], |
|
|
@ -498,7 +484,37 @@ def getzuobi(): |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# 警告学生 |
|
|
|
@app.route("/jinggao", methods=["post"]) |
|
|
|
def jinggao(): |
|
|
|
resData = request.data |
|
|
|
# 获取到POST过来的数据,转为json形式 |
|
|
|
userJson = json.loads(resData) |
|
|
|
studentId = userJson["studentId"] |
|
|
|
sid = "" |
|
|
|
for item in clients: |
|
|
|
if item["id"] == studentId: |
|
|
|
sid = item["sid"] |
|
|
|
message = {"type": "jinggao", "data": "请遵守考试规则"} |
|
|
|
socketio.emit("studentMsg" + studentId, message, to=sid) |
|
|
|
zuobiItem = { |
|
|
|
"userId": studentId, |
|
|
|
"msg": message["data"], |
|
|
|
"type": "jinggao", |
|
|
|
"create_at": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())), |
|
|
|
"update_at": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())), |
|
|
|
"isExit": 1, |
|
|
|
} |
|
|
|
addzuobi(zuobiItem) |
|
|
|
return { |
|
|
|
"code": 200, |
|
|
|
"msg": "警告成功", |
|
|
|
"list": [], |
|
|
|
"hasError": False, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
initData() |
|
|
|
# app.run(debug=True) |
|
|
|
socketio.run(app, host='0.0.0.0', port=5000, debug=True) |
|
|
|
socketio.run(app, host="0.0.0.0", port=5000, debug=True) |
|
|
|