私は顔検出アプリケーションで働いています。画像内で検出されたすべての顔のバウンディングボックス座標を取得する必要があります。これはコードであり、問題は、多くの面が検出されたシナリオでのみ、1つの面のbbox座標を出力することです。
import mxnet as mx
import cv2
import os
detector = MtcnnDetector(model_folder='model', ctx=mx.cpu(0))
img = cv2.imread("amm.png")
results = detector.detect_face(img, False)
t2 = time.time() -t1
print("time: ",t2)
if results is not None:
total_boxes = results[0]
points = results[1]
draw = img.copy()
for b in total_boxes:
cv2.rectangle(draw, (int(b[0]), int(b[1])), (int(b[2]), int(b[3])),(250, 100, 0),1)
face_count = 0 # counting number of detected faces within the image
for b in total_boxes:
face_count +=1
print("detected faces" , face_count) # printing number of detected faces.
# I want to print the x and y coordinates of every faces detected
for z in b :
print(int(z), end=" ", flush=True)
だからこれは私が得た結果です:
検出された面
12199 302 257 377 0(このbboxは1つの面のみで、12の面が検出されました)
誰かが私が検出されたすべての顔のbboxを取得する方法を理解するのを手伝ってもらえますか?
前もって感謝します
total_boxes
座標を印刷するために繰り返す必要があります。
交換するfor z in b :
とfor z in total_boxes :
したがって、更新されたコードは次のようになります。
for box in total_boxes: for coord in box: print(int(coord), end=" ", flush=True) print()
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加