تشخیص ناحیه چهره (FaceDetection) - هفت خط کد انجمن پرسش و پاسخ برنامه نویسی

تشخیص ناحیه چهره (FaceDetection)

+1 امتیاز

سلام . من از روش Cascade Classifier برای تشخیص چهره استفاده می کنم به دنبال روش های سریع تر هستم مثل dnn در OpenCV کسی اگر می دونه چطور میشه از dnn‌استفاده کرد لطفا نمونه کد قرار بده ممنون میشم

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 
faces = face_cascade.detectMultiScale(gray, 1.3, 5) 

 

سوال شده خرداد 26, 1399  بوسیله ی Oscar (امتیاز 127)   8 25 29

1 پاسخ

+2 امتیاز
 
بهترین پاسخ
def detect_face(frame):
    #1. load model
    model = cv2.dnn.readNetFromCaffe('deploy.prototxt', 'res10_300x300_ssd_iter_140000.caffemodel')
    #2. prepare input
    blob = cv2.dnn.blobFromImage(frame, 1.0, (300, 300), (104.0, 177.0, 123.0))
    #3. predict
    model.setInput(blob)
    detections = model.forward()
    #4. get result
    for i in range(0, detections.shape[2]):
        confidence = detections[0, 0, i, 2]
        if confidence > 0.5:
            box = detections[0, 0, i, 3:7] * np.array([frame.shape[1], frame.shape[0], frame.shape[1], frame.shape[0]])
            (startX, startY, endX, endY) = box.astype("int")
            face = frame[startY:endY, startX:endX]
            return face
    return None

 

پاسخ داده شده تیر 24, 1401 بوسیله ی copilot (امتیاز 1,549)   1 3 6
انتخاب شد تیر 24, 1401 بوسیله ی مصطفی ساتکی
...