每当我的面部检测python脚本检测到面部时,我都试图显示图像。因此,我需要一个允许我执行此操作的函数,并且我考虑要在Flask上显示HTML上的人脸捕获图像。我必须像中继器一样进行面部检测,以便每当检测到新面孔时,它将实时/动态地显示在页面上。
这是我现在拥有的:
class RandomThread(Thread):
def __init__(self):
self.delay = 1
super(RandomThread, self).__init__()
def randomNumberGenerator(self):
print("Making random numbers")
while not thread_stop_event.isSet():
number = round(random()*10, 3)
print(number)
image_src = "8.png"
socketio.emit('newImage', {'image': image_src}, namespace='/test')
socketio.emit('newnumber', {'number': number}, namespace='/test')
with open('8.png', 'rb') as f:
image_data = f.read()
socketio.emit('my-image-event', {'image_data': image_data})
sleep(self.delay)
def run(self):
self.randomNumberGenerator()
# self.randomNewImage()
通过https://www.shanelynn.ie/asynchronous-updates-to-a-webpage-with-flask-and-socket-io/