| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
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)
 
  复制代码 
 
 |   
 
 
 
 |