forked from chack1920/tensorflow_face_recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
743d10f
commit 06e4cb9
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from flask import Flask | ||
from multiprocessing import Process | ||
import re | ||
import os | ||
import time | ||
import sys | ||
import face_recognition_dlib_tensorflow as frdt | ||
|
||
app = Flask(__name__) | ||
|
||
@app.before_first_request | ||
def before_first_request(): | ||
flask_pid = os.popen("ps -ef |grep flask").readlines() | ||
f = open("info.txt", 'a') | ||
pid = re.findall("\d+",flask_pid[0])[0] | ||
f.writelines(pid+"\n") | ||
f.close() | ||
|
||
@app.route('/start') | ||
def start(): | ||
P = Process(target=frdt.main_process(),args=()) | ||
P.start() | ||
return "<h1>摄像头已打开</h1>" | ||
|
||
@app.route('/finish') | ||
def finish(): | ||
with open("info.txt",'r') as f: | ||
info_list = f.readlines() | ||
flask_temp = 0 | ||
for i in range(len(info_list)): | ||
temp = re.findall('\d+$', info_list[i]) | ||
if temp: | ||
flask_temp = temp[0] | ||
print(flask_temp) | ||
pid_list = os.popen("ps -ef | grep flask").readlines() | ||
print(pid_list) | ||
for i in range(len(pid_list)): | ||
pid_list[i] = pid_list[i].split()[1] | ||
print(pid_list) | ||
if str(pid_list[i]) != flask_temp and flask_temp != 0: | ||
try: | ||
os.popen("kill -15 " + str(pid_list[i])) | ||
except: | ||
os.popen("kill -9 " + str(pid_list[i])) | ||
print("kill " + str(pid_list[i]) + "\n") | ||
if os.path.exists("info.txt"): | ||
os.remove("info.txt") | ||
time.sleep(4) | ||
sys.exit() | ||
|
||
return "<h1>摄像头已关闭</h1>" |