人臉偵測

Python 影像處理

Rebeca Gonzalez

Data Engineer

人臉偵測:應用案例

  • 濾鏡
  • 自動對焦
  • 推薦
  • 模糊處理以保護隱私
  • 之後辨識情緒

Python 影像處理

使用 scikit-image 偵測人臉

Python 影像處理

使用 scikit-image 偵測人臉

# Import the classifier class
from skimage.feature import Cascade

# Load the trained file from the module root. trained_file = data.lbp_frontal_face_cascade_filename()
# Initialize the detector cascade. detector = Cascade(trained_file)
Python 影像處理

來試試看

Python 影像處理

人臉偵測

Python 影像處理

人臉偵測

Python 影像處理

人臉偵測

# Apply detector on the image
detected = detector.detect_multi_scale(img=image,

scale_factor=1.2,
step_ratio=1,
min_size=(10, 10), max_size=(200, 200))
Python 影像處理

已偵測的人臉

print(detected)

# Show image with detected face marked show_detected_face(image, detected)
Detected face: [{'r': 115, 'c': 210, 'width': 167, 'height': 167}]

Python 影像處理

顯示偵測到的人臉

def show_detected_face(result, detected, title="Face image"):
    plt.imshow(result)
    img_desc = plt.gca()
    plt.set_cmap('gray')
    plt.title(title)
    plt.axis('off')

    for patch in detected:
        img_desc.add_patch(
            patches.Rectangle(
                (patch['c'], patch['r']),
                patch['width'],
                patch['height'],
                fill=False,color='r',linewidth=2)
        )
    plt.show()
Python 影像處理

一起來練習吧!

Python 影像處理

Preparing Video For Download...