gpt4 book ai didi

python - 如何使用 IP Cam 代替 USB Web Cam 检测/识别人脸

转载 作者:太空宇宙 更新时间:2023-11-03 22:37:38 25 4
gpt4 key购买 nike

我正在学习和从事人脸识别大学项目。

人脸识别.py

from imutils.video import VideoStream
import face_recognition
import argparse
import imutils
import pickle
import time
import cv2

ap = argparse.ArgumentParser()
ap.add_argument("-e", "--encodings", required=True,
help="path to serialized db of facial encodings")
ap.add_argument("-o", "--output", type=str,
help="path to output video")
ap.add_argument("-y", "--display", type=int, default=1,
help="whether or not to display output frame to screen")
ap.add_argument("-d", "--detection-method", type=str, default="cnn",
help="face detection model to use: either `hog` or `cnn`")
args = vars(ap.parse_args())

print("[INFO] loading encodings...")
data = pickle.loads(open(args["encodings"], "rb").read())

print("[INFO] starting video stream...")
vs = VideoStream(src=0).start()
writer = None
time.sleep(2.0)

while True:
frame = vs.read()

rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
rgb = imutils.resize(frame, width=260)
r = frame.shape[0] / float(rgb.shape[0])

boxes = face_recognition.face_locations(rgb,
model=args["detection_method"])
encodings = face_recognition.face_encodings(rgb, boxes)
names = []

for encoding in encodings:

matches = face_recognition.compare_faces(data["encodings"],
encoding)
name = "Unknown"

if True in matches:

matchedIdxs = [i for (i, b) in enumerate(matches) if b]
counts = {}

for i in matchedIdxs:
name = data["names"][i]
counts[name] = counts.get(name, 0) + 1

name = max(counts, key=counts.get)

names.append(name)

for ((top, right, bottom, left), name) in zip(boxes, names):

top = int(top * r)
right = int(right * r)
bottom = int(bottom * r)
left = int(left * r)

cv2.rectangle(frame, (left, top), (right, bottom),
(0, 255, 0), 2)
y = top - 15 if top - 15 > 15 else top + 15
cv2.putText(frame, name, (left, y), cv2.FONT_HERSHEY_SIMPLEX,
0.75, (0, 255, 0), 2)

if writer is None and args["output"] is not None:
fourcc = cv2.VideoWriter_fourcc(*"MJPG")
writer = cv2.VideoWriter(args["output"], fourcc, 20,
(frame.shape[1], frame.shape[0]), True)

if writer is not None:
writer.write(frame)

if args["display"] > 0:
cv2.imshow("Frame", frame)
key = cv2.waitKey(1) & 0xFF

if key == ord("q"):
break

cv2.destroyAllWindows()
vs.stop()

if writer is not None:
writer.release()

我可以使用带有此代码的 USB 摄像头检测和识别人脸,但现在

我想使用 IP Cam 而不是 USB Cam 进行检测。我的 CP PLUS IP CAM 在 192.168.1.181 上运行,我想使用该摄像头来检测和识别人脸。

如何在此代码中使用该 IP CAM?

最佳答案

在您的代码中只需更改一行,vs = VideoStream(src="192.168.1.181/cam/realmonitorchannel=1&subtype=1&unicast=true&proto=Onvif").start()让我知道它是否有效。

关于python - 如何使用 IP Cam 代替 USB Web Cam 检测/识别人脸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56823012/

25 4 0
文章推荐: Python 和 OpenCV : Realtime Get RGB Values When Mouse Is Clicked
文章推荐: c# - Asp.Net Core 2.2 身份页面不能与 View /共享文件夹中的布局一起使用
文章推荐: html - 我怎样才能让这个
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com