開始使用免費開始

分割與人臉偵測

先前你已學過如何用無監督的超像素分割來提升運算效率。這個練習就要你實作看看!

使用 slic() 函式進行分割,先對影像做前處理,再把結果送進人臉偵測器。

Young woman selfie
影像已預先載入為 profile_image

Cascade 類別、segmentation 模組中的 slic() 函式,以及用於視覺化的 show_detected_face() 函式都已匯入。偵測器也已初始化為 detector,可直接使用。

本練習屬於課程

Python 影像處理

檢視課程

練習說明

  • 使用 slic() 進行超像素分割,取得分割結果(即標籤,labels)。
  • 使用 label2rgb() 取得分割後影像,並傳入 segmentsprofile_image
  • 使用偵測器的 multi scale 方法進行人臉偵測。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Obtain the segmentation with default 100 regions
segments = ____

# Obtain segmented image using label2rgb
segmented_image = ____(____, ____, kind='avg')

# Detect the faces with multi scale method
detected = detector.____(img=____, 
                                       scale_factor=1.2, 
                                       step_ratio=1, 
                                       min_size=(10, 10), max_size=(1000, 1000))

# Show the detected faces
show_detected_face(segmented_image, detected)
編輯並執行程式碼