实时人脸摄像头检测

# -*- coding: utf-8 -*-
import face_recognition
import cv2
rtsp_url='rtsp://admin:123456@192.168.2.244:554/Streaming/Channels/101?transportmode=multicast'
#rtsp_url='G:/cascades/aobama.mp4'
#rtsp_url='G:/cascades/video1.mp4'
#rtsp_url='G:/cascades/limingzhou.mp4'
video_capture = cv2.VideoCapture(rtsp_url)

#obama_img = face_recognition.load_image_file("G:/cascades/obama11.jpg") 修改第一处
#wzr_img = face_recognition.load_image_file("G:/cascades/wzr.jpg")
lmz_img = face_recognition.load_image_file("G:/cascades/lmz.jpg")
#obama_face_encoding = face_recognition.face_encodings(obama_img)[0]   修改第二处
lmz_face_encoding = face_recognition.face_encodings(lmz_img)[0]
face_locations = []
face_encodings = []
face_names = []
process_this_frame = True

while True:
    ret, frame = video_capture.read()

    small_frame = cv2.resize(frame, (0,0), fx=0.25, fy=0.25)

    if process_this_frame:
        face_locations = face_recognition.face_locations(small_frame)
        face_encodings = face_recognition.face_encodings(small_frame, face_locations)

        face_names = []
        for face_encoding in face_encodings:
            match = face_recognition.compare_faces([lmz_face_encoding], face_encoding)
            #match = face_recognition.compare_faces([wzr_face_encoding], face_encoding)
            #match = face_recognition.compare_faces([obama_face_encoding], face_encoding) 修改第三处

            if match[0]:
                name = "limingzhou"
            else:
                name = "unknown"

            face_names.append(name)

    process_this_frame = not process_this_frame

    for (top, right, bottom, left), name in zip(face_locations, face_names):
        top *= 4
        right *= 4
        bottom *= 4
        left *= 4

        cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255),  2)

        cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), 2)
        font = cv2.FONT_HERSHEY_DUPLEX
        cv2.putText(frame, name, (left+6, bottom-6), font, 1.0, (255, 255, 255), 1)

    cv2.imshow('Video', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

video_capture.release()
cv2.destroyAllWindows()

参考网站:https://blog.csdn.net/hongbin_xu/article/details/76284134

参考问题:如果自己的录的视频无法识别,请用格式工厂修改一下视频格式和图片格式

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值