神州电脑人脸识别开机_Python人脸识别之谁偷用了我的电脑?

很久很久以前,我就在想,要是谁偷偷用了我的电脑,电脑能主动拍照并发邮件通知给我多好啊。

0d37be3c8beb465d2a421c5af25ec93d.png

现在,通过人脸识别开源库,我们百多行代码就能够实现这个功能。

我们可以通过windows来设置开机启动或者定时任务,我们只需要关心软件启动后,识别到陌生人给我们发邮件这个逻辑就好了。

技术选择

人脸识别我们采用github上的face_recognition这个软件,摄像头调用我们采用OpenCV来捕捉图像,邮件我们通过Python的email模块来发送邮件。

主逻辑

  1. 软件启动后,循环调用摄像头获取图片。
  2. 获取图片后,通过face_recognition来识别是否是管理员。
  3. 如果满足陌生人的条件,比如10次识别的正确次数小于8,就发邮件通知自己。

示例代码

ret, frame = video_capture.read() small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) rgb_small_frame = small_frame[:, :, ::-1] face_locations = face_recognition.face_locations(rgb_small_frame) face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations) is_me = [] for face_encoding in face_encodings: matches = face_recognition.compare_faces([i_face_encoding], face_encoding, tolerance) if True in matches: is_me.append(1) else: is_me.append(0) if debug: if debug_send_mail: mail.thread_send_mail(email_text.debug_header, email_text.debug_text) debug_send_mail = False for (top, right, bottom, left), this_is_me in zip(face_locations, is_me): top *= 4 right *= 4 bottom *= 4 left *= 4 color = (101, 67, 254) name = 'stranger' if this_is_me == 1: color = (155, 175, 131) name = 'me' cv2.rectangle(frame, (left, top), (right, bottom), color, 2) cv2.rectangle(frame, (left, bottom - 35), (right, bottom), color, cv2.FILLED) cv2.putText(frame, name, (left + 6, bottom - 6), cv2.FONT_HERSHEY_DUPLEX, 1.0, (255, 255, 255), 1) cv2.imshow(win_name, frame) if cv2.waitKey(1) & 0xFF == ord('q'): break if cv2.getWindowProperty(win_name, cv2.WND_PROP_AUTOSIZE) < 1: break else: cv2.waitKey(5) print(count, 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值