質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

704閲覧

OpenCVでの顔認識

RiveraJoel

総合スコア5

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/01/11 12:10

前提・実現したいこと

プログラム初心者です。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/ツールのバージョンなど)

必要なのはとにかくあたらしいのをダウンロードしました

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

python recognize.py --detector face_detection_model
--embedding-model openface_nn4.small2.v1.t7
--recognizer output/recognizer.pickle
--le output/le.pickle --image images/adrian.jpg

投稿2020/01/14 12:04

RiveraJoel

総合スコア5

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

ベストアンサー

extract_embeddings.py: error: 次の引数が必要です。

-i/--dataset, -e/--embeddings, -d/--detector, -m/--embedding-model

といってるんですから、そのとおりにやってみたらどうでしょうか

投稿2020/01/11 12:21

y_waiwai

総合スコア87774

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Q71

2020/01/11 13:51

そして、ウェブに引数の説明もされていますね
RiveraJoel

2020/01/14 07:06

コマンド引数について知識がなく焦っていたようで必要な引数もわかりませんでした よくみたらプログラム自体に必要な引数が書いてありますね どうもありがとうございました
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問