yayc_zcyd 发表于 2022-8-14 17:08:15

Python人脸识别报错


这个人脸识别在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(" loading face detector model...")
prototxtPath = os.path.sep.join()
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(" computing face detections...")
net.setInput(blob)
detections = net.forward()
for i in range(0, detections.shape):
        confidence = detections
        if confidence > args["confidence"]:
                box = detections * np.array()
                (startX, startY, endX, endY) = box.astype("int")
                face = image
                if args["method"] == "pixelated":
                        face = anonymize_face_simple(face, factor=3.0)
                else:
                        face = anonymize_face_pixelate(face,
                                blocks=args["blocks"])
                image = face
output = np.hstack()
cv2.imshow("Output", output)
cv2.waitKey(0)

yayc_zcyd 发表于 2022-8-17 09:54:09

已解决
页: [1]
查看完整版本: Python人脸识别报错