|
|
|
@@ -7,6 +7,8 @@ import datetime |
|
|
|
import os |
|
|
|
import sys |
|
|
|
from utils.utils import send_notifycation |
|
|
|
import collections |
|
|
|
from utils.utils import doNotMove,mouseClick |
|
|
|
|
|
|
|
def getFile(ruleFile): |
|
|
|
if getattr(sys, 'frozen', False): |
|
|
|
@@ -25,6 +27,10 @@ def get_settings_status_name(data, settings,setting_name): |
|
|
|
# 使用 filter() 和 map() 函数提取信息 |
|
|
|
names = list(map(lambda x: x["name"], filter(lambda x: x["status"], setting["status"]))) |
|
|
|
return names[0] |
|
|
|
def get_settings_status_root(data, settings): |
|
|
|
# 访问指定 "setting" 的信息 |
|
|
|
names = list(map(lambda x: x["name"], filter(lambda x: x["status"], data[settings]))) |
|
|
|
return names[0] |
|
|
|
def get_setting_status(data, settings,setting_name): |
|
|
|
# 使用 filter() 和 map() 函数提取信息 |
|
|
|
status = list(map(lambda x: x["status"], filter(lambda x: x["name"] == setting_name, data[settings]))) |
|
|
|
@@ -82,6 +88,30 @@ def getModelSetting(args): |
|
|
|
model["status"] = False |
|
|
|
args["ModelSetting"][0]["status"] = model_dict |
|
|
|
return args |
|
|
|
def checkAction(queue,type,action,tip): |
|
|
|
print(type,action,queue[2]["time"]-queue[0]["time"]) |
|
|
|
# 输入一个长度为3的队列,根据情况判断是否执行动作 |
|
|
|
if(queue[0]["status"]==0 and queue[1]["status"]==1 and queue[2]["status"]==0 and type=="张开持续1S" and (queue[2]["time"]-queue[0]["time"])>1): |
|
|
|
if(action=="悬停鼠标"): |
|
|
|
doNotMove() |
|
|
|
if(tip): |
|
|
|
send_notifycation("触发悬停鼠标","EMC") |
|
|
|
elif(action=="单击按钮"): |
|
|
|
mouseClick() |
|
|
|
if(tip): |
|
|
|
send_notifycation("触发单击按钮","EMC") |
|
|
|
return True |
|
|
|
elif(queue[0]["status"]==1 and queue[1]["status"]==0 and queue[2]["status"]==1 and type=="闭上持续1S" and (queue[2]["time"]-queue[0]["time"])>1): |
|
|
|
if(action=="悬停鼠标"): |
|
|
|
doNotMove() |
|
|
|
if(tip): |
|
|
|
send_notifycation("触发悬停鼠标","EMC") |
|
|
|
elif(action=="单击按钮"): |
|
|
|
mouseClick() |
|
|
|
if(tip): |
|
|
|
send_notifycation("触发单击按钮","EMC") |
|
|
|
return True |
|
|
|
return False |
|
|
|
|
|
|
|
class API: |
|
|
|
'''本地API,供前端JS调用''' |
|
|
|
@@ -89,6 +119,8 @@ class API: |
|
|
|
net = None |
|
|
|
cap = None |
|
|
|
args = None |
|
|
|
# 状态队列 |
|
|
|
queue = None |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self): |
|
|
|
@@ -108,9 +140,55 @@ class API: |
|
|
|
|
|
|
|
# cv2.namedWindow('Video Cam', cv2.WINDOW_NORMAL) |
|
|
|
if(self.args['toggle'] and self.args['tip']): |
|
|
|
send_notifycation("功能触发:鼠标悬停","EMC[嘴控]") |
|
|
|
send_notifycation("EMC程序已启动","EMC") |
|
|
|
|
|
|
|
self.queue = collections.deque(maxlen=3) |
|
|
|
|
|
|
|
def detectThreading(self): |
|
|
|
if self.args['toggle']==False: |
|
|
|
pass |
|
|
|
result = get_photo_detect(self.cap,self.net) |
|
|
|
eye = -1 |
|
|
|
mouth = -1 |
|
|
|
for i in result: |
|
|
|
if i["classid"] == "closed_eye": |
|
|
|
eye = 0 |
|
|
|
elif i["classid"] == "open_eye": |
|
|
|
eye = 1 |
|
|
|
elif i["classid"] == "closed_mouth": |
|
|
|
mouth = 0 |
|
|
|
elif i["classid"] == "open_mouth": |
|
|
|
mouth = 1 |
|
|
|
|
|
|
|
|
|
|
|
status = -1 |
|
|
|
|
|
|
|
if get_settings_status_root(self.args,"control") == "嘴控": |
|
|
|
if(mouth==0): |
|
|
|
status = 0 |
|
|
|
elif(mouth==1): |
|
|
|
status = 1 |
|
|
|
elif get_settings_status_root(self.args,"control") == "眼控": |
|
|
|
if(eye==0): |
|
|
|
status = 0 |
|
|
|
elif(eye==1): |
|
|
|
status = 1 |
|
|
|
elif get_settings_status_root(self.args,"control") == "嘴/眼控": |
|
|
|
if(mouth==0 or eye==0): |
|
|
|
status = 0 |
|
|
|
elif(mouth==1 or eye==1): |
|
|
|
status = 1 |
|
|
|
|
|
|
|
if(status!=-1): |
|
|
|
if(len(self.queue)<3 or status!=self.queue[-1]["status"]): |
|
|
|
self.queue.append({"status":status,"time":time.time()}) |
|
|
|
if(len(self.queue)==3): |
|
|
|
if(checkAction(self.queue,get_settings_status_name(self.args,"ControlSetting","控制设置"),get_settings_status_name(self.args,"ControlSetting","控制功能"),self.args['tip'])): |
|
|
|
self.queue.clear()#执行动作则清空队列 |
|
|
|
else: |
|
|
|
self.queue[-1]["time"]=time.time() |
|
|
|
print(self.queue) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getPrimaryImg(self,type="不裁剪"): |
|
|
|
# 三种处理图片的方式:不裁剪、居中裁剪成224*224、居中裁剪成320*320。 |
|
|
|
|