前提・実現したいこと
プログラム初心者です。OpenCVで顔認識の機能を試しています。
https://www.pyimagesearch.com/2018/09/24/opencv-face-recognition/
こちらのサイトを参考にしダウンロードしたコードを試していました。
その中のrecognize.py機能を実装中に以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
usage: extract_embeddings.py [-h] -i DATASET -e EMBEDDINGS -d DETECTOR -m EMBEDDING_MODEL [-c CONFIDENCE] extract_embeddings.py: error: the following arguments are required: -i/--dataset, -e/--embeddings, -d/--detector, -m/--embedding-model
該当のソースコード
python
1# USAGE 2# python recognize.py --detector face_detection_model \ 3# --embedding-model openface_nn4.small2.v1.t7 \ 4# --recognizer output/recognizer.pickle \ 5# --le output/le.pickle --image images/adrian.jpg 6 7# import the necessary packages 8import numpy as np 9import argparse 10import imutils 11import pickle 12import cv2 13import os 14 15# construct the argument parser and parse the arguments 16ap = argparse.ArgumentParser() 17ap.add_argument("-i", "--image", required=True, 18 help="path to input directory of faces + images") 19ap.add_argument("-d", "--detector", required=True, 20 help="path to OpenCV's deep learning face detector") 21ap.add_argument("-m", "--embedding-model", required=True, 22 help="path to OpenCV's deep learning face embedding model") 23ap.add_argument("-r", "--recognizer", required=True, 24 help="path to model trained to recognize faces") 25ap.add_argument("-l", "--le", required=True, 26 help="path to label encoder") 27ap.add_argument("-c", "--confidence", type=float, default=0.5, 28 help="minimum probability to filter weak detections") 29args = vars(ap.parse_args()) 30 31 32 33# load our serialized face detector from disk 34print("[INFO] loading face detector...") 35protoPath = os.path.sep.join([args["detector"], "deploy.prototxt"]) 36modelPath = os.path.sep.join([args["detector"], 37 "res10_300x300_ssd_iter_140000.caffemodel"]) 38detector = cv2.dnn.readNetFromCaffe(protoPath, modelPath) 39 40# load our serialized face embedding model from disk 41print("[INFO] loading face recognizer...") 42embedder = cv2.dnn.readNetFromTorch(args["embedding_model"]) 43 44# load the actual face recognition model along with the label encoder 45recognizer = pickle.loads(open(args["recognizer"], "rb").read()) 46le = pickle.loads(open(args["le"], "rb").read()) 47 48# load the image, resize it to have a width of 600 pixels (while 49# maintaining the aspect ratio), and then grab the image dimensions 50image = cv2.imread(args["image"]) 51image = imutils.resize(image, width=600) 52(h, w) = image.shape[:2] 53 54# construct a blob from the image 55imageBlob = cv2.dnn.blobFromImage( 56 cv2.resize(image, (300, 300)), 1.0, (300, 300), 57 (104.0, 177.0, 123.0), swapRB=False, crop=False) 58 59# apply OpenCV's deep learning-based face detector to localize 60# faces in the input image 61detector.setInput(imageBlob) 62detections = detector.forward() 63 64# loop over the detections 65for i in range(0, detections.shape[2]): 66 # extract the confidence (i.e., probability) associated with the 67 # prediction 68 confidence = detections[0, 0, i, 2] 69 70 # filter out weak detections 71 if confidence > args["confidence"]: 72 # compute the (x, y)-coordinates of the bounding box for the 73 # face 74 box = detections[0, 0, i, 3:7] * np.array([w, h, w, h]) 75 (startX, startY, endX, endY) = box.astype("int") 76 77 # extract the face ROI 78 face = image[startY:endY, startX:endX] 79 (fH, fW) = face.shape[:2] 80 81 # ensure the face width and height are sufficiently large 82 if fW < 20 or fH < 20: 83 continue 84 85 # construct a blob for the face ROI, then pass the blob 86 # through our face embedding model to obtain the 128-d 87 # quantification of the face 88 faceBlob = cv2.dnn.blobFromImage(face, 1.0 / 255, (96, 96), 89 (0, 0, 0), swapRB=True, crop=False) 90 embedder.setInput(faceBlob) 91 vec = embedder.forward() 92 93 # perform classification to recognize the face 94 preds = recognizer.predict_proba(vec)[0] 95 j = np.argmax(preds) 96 proba = preds[j] 97 name = le.classes_[j] 98 99 # draw the bounding box of the face along with the associated 100 # probability 101 text = "{}: {:.2f}%".format(name, proba * 100) 102 y = startY - 10 if startY - 10 > 10 else startY + 10 103 cv2.rectangle(image, (startX, startY), (endX, endY), 104 (0, 0, 255), 2) 105 cv2.putText(image, text, (startX, y), 106 cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2) 107 108# show the output image 109cv2.imshow("Image", image) 110cv2.waitKey(0) 111
試したこと
ページ内に同じことが起こっている人は多いようでそのことに対して別ページで解説されていたのですが結局どうすればいいのかがいまいちわかりませんでした
補足情報(FW/ツールのバージョンなど)
必要なのはとにかくあたらしいのをダウンロードしました
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。