林清浅
2021-01-26 13:28
采纳率: 66.7%
浏览 42

在用opencv时遇到这个问题,请问该怎么解决?

detector = cv2.dnn.readNetFromCaffe(protoPath="D:/opencv-face-recognition/face_detection_model/deploy.prototxt", modelPath="D:/opencv-face-recognition/face_detection_model/res10_300x300_ssd_iter_140000.caffemodel")
TypeError: readNetFromCaffe() missing required argument 'bufferProto' (pos 1)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • Bryce__LY 2021-01-26 13:48
    已采纳

    你试试这个 cv2.dnn.readNetFromCaffe("D:/opencv-face-recognition/face_detection_model/deploy.prototxt", "D:/opencv-face-recognition/face_detection_model/res10_300x300_ssd_iter_140000.caffemodel")

    点赞 打赏 评论
  • 无厘头编程 2021-01-26 13:48

    bufferProto: prototxt 这个文件没找着。就是 你 的 D:/opencv-face-recognition/face_detection_model/deploy.prototxt

    点赞 打赏 评论
  • 无厘头编程 2021-01-26 13:52

    Python 文件:

    readNetFromCaffe(bufferProto[, bufferModel]) -> retval
    .   @brief Reads a network model stored in Caffe model in memory.
    .   * @param bufferProto buffer containing the content of the .prototxt file
    .   * @param bufferModel buffer containing the content of the .caffemodel file
    .   * @returns Net object.

    因此,查文件在哪里,路径和文件名称合理吗?(名字对吗?有没有奇怪的字母)

    点赞 打赏 评论
  • 无厘头编程 2021-01-27 02:28

    文件检查加成:

    import os
    import cv2
    
    # *.prototxt :模型构成
    proto = 'D:/opencv-face-recognition/face_detection_model/deploy.prototxt'
    
    # *.caffemodel:比重,画层
    model = 'D:/opencv-face-recognition/face_detection_model/res10_300x300_ssd_iter_140000.caffemodel'
    
    exist = os.path.exists(proto)
    print('deploy.prototxt, 有吗? ', exist)
    exist = os.path.exists(model)
    print('res10_300x300_ssd_iter_140000.caffemodel, 有吗? ', exist)
    
    # load model
    print("[INFO] 启动 model...")
    net = cv2.dnn.readNetFromCaffe(proto, model)
    print(net)
    点赞 打赏 评论
  • 无厘头编程 2021-01-27 02:48
    这个更好,直接掐断:
    def file_check(filename):
        exist = os.path.exists(filename)
        if not exist:
            raise FileNotFoundError(
                errno.ENOENT, os.strerror(errno.ENOENT), filename)
    
    
    iris_file = 'D:/tensorflow/iris_training.csq'
    file_check(iris_file)
    print('file found: ', iris_file)
    点赞 打赏 评论

相关推荐 更多相似问题