鱼C论坛

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

Python人脸识别报错

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

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

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

x

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


就是这个↑
报错信息:
  1. 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'
复制代码


源代码:
  1. from zy.face_blurring import anonymize_face_pixelate
  2. from zy.face_blurring import anonymize_face_simple
  3. import numpy as np
  4. import argparse
  5. import cv2
  6. import os
  7. ap = argparse.ArgumentParser()
  8. ap.add_argument("-m", "--method", type=str, default="simple",
  9.         choices=["simple", "pixelated"],
  10.         help="face blurring/anonymizing method")
  11. ap.add_argument("-b", "--blocks", type=int, default=20,
  12.         help="# of blocks for the pixelated blurring method")
  13. ap.add_argument("-c", "--confidence", type=float, default=0.5,
  14.         help="minimum probability to filter weak detections")
  15. args = vars(ap.parse_args())
  16. print("[INFO] loading face detector model...")
  17. prototxtPath = os.path.sep.join([r'D:\opencv-face-blurring\face_detector', "deploy.prototxt"])
  18. weightsPath = os.path.sep.join([r'D:\opencv-face-blurring\face_detector',
  19.         "res10_300x300_ssd_iter_140000.caffemodel"])
  20. net = cv2.dnn.readNet(prototxtPath, weightsPath)
  21. image = cv2.imread(r'D:\opencv-face-blurring\examples\zy.png')
  22. orig = image.copy()
  23. (h, w) = image.shape[:2]
  24. blob = cv2.dnn.blobFromImage(image, 1.0, (300, 300),
  25.         (104.0, 177.0, 123.0))
  26. print("[INFO] computing face detections...")
  27. net.setInput(blob)
  28. detections = net.forward()
  29. for i in range(0, detections.shape[2]):
  30.         confidence = detections[0, 0, i, 2]
  31.         if confidence > args["confidence"]:
  32.                 box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
  33.                 (startX, startY, endX, endY) = box.astype("int")
  34.                 face = image[startY:endY, startX:endX]
  35.                 if args["method"] == "pixelated":
  36.                         face = anonymize_face_simple(face, factor=3.0)
  37.                 else:
  38.                         face = anonymize_face_pixelate(face,
  39.                                 blocks=args["blocks"])
  40.                 image[startY:endY, startX:endX] = face
  41. output = np.hstack([orig, image])
  42. cv2.imshow("Output", output)
  43. cv2.waitKey(0)
复制代码


小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-8-17 09:54:09 | 显示全部楼层
已解决
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-27 15:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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