鱼C论坛

 找回密码
 立即注册
查看: 1952|回复: 1

Python人脸识别报错

[复制链接]
发表于 2022-8-14 17:08:15 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

这个人脸识别在20行会报错
net = cv2.dnn.readNet(prototxtPath, weightsPath)

就是这个↑
报错信息:
cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\caffe\caffe_io.cpp:1126: error: (-2:Unspecified error) FAILED: fs.is_open(). Can't open "D:\opencv-face-blurring\face_detector\deploy.prototxt" in function 'cv::dnn::ReadProtoFromTextFile'

源代码:
from zy.face_blurring import anonymize_face_pixelate
from zy.face_blurring import anonymize_face_simple
import numpy as np
import argparse
import cv2
import os
ap = argparse.ArgumentParser()
ap.add_argument("-m", "--method", type=str, default="simple",
        choices=["simple", "pixelated"],
        help="face blurring/anonymizing method")
ap.add_argument("-b", "--blocks", type=int, default=20,
        help="# of blocks for the pixelated blurring method")
ap.add_argument("-c", "--confidence", type=float, default=0.5,
        help="minimum probability to filter weak detections")
args = vars(ap.parse_args())
print("[INFO] loading face detector model...")
prototxtPath = os.path.sep.join([r'D:\opencv-face-blurring\face_detector', "deploy.prototxt"])
weightsPath = os.path.sep.join([r'D:\opencv-face-blurring\face_detector',
        "res10_300x300_ssd_iter_140000.caffemodel"])
net = cv2.dnn.readNet(prototxtPath, weightsPath)
image = cv2.imread(r'D:\opencv-face-blurring\examples\zy.png')
orig = image.copy()
(h, w) = image.shape[:2]
blob = cv2.dnn.blobFromImage(image, 1.0, (300, 300),
        (104.0, 177.0, 123.0))
print("[INFO] computing face detections...")
net.setInput(blob)
detections = net.forward()
for i in range(0, detections.shape[2]):
        confidence = detections[0, 0, i, 2]
        if confidence > args["confidence"]:
                box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
                (startX, startY, endX, endY) = box.astype("int")
                face = image[startY:endY, startX:endX]
                if args["method"] == "pixelated":
                        face = anonymize_face_simple(face, factor=3.0)
                else:
                        face = anonymize_face_pixelate(face,
                                blocks=args["blocks"])
                image[startY:endY, startX:endX] = face
output = np.hstack([orig, image])
cv2.imshow("Output", output)
cv2.waitKey(0)

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-8-17 09:54:09 | 显示全部楼层
已解决
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-29 12:21

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表