注意
前往結尾以下載完整的範例程式碼。或透過 Binder 在您的瀏覽器中執行此範例
Haar 類特徵描述子#
Haar 類特徵是簡單的數位影像特徵,它是在即時臉部偵測器中引入的 [1]。 使用積分影像 [1],這些特徵可以在任何尺度上以恆定的時間有效地計算。 之後,從這個大量潛在特徵中選擇少量關鍵特徵 (例如,使用 AdaBoost 學習演算法,如 [1])。 以下範例將展示如何建構此系列描述子的機制。
參考文獻#
import numpy as np
import matplotlib.pyplot as plt
from skimage.feature import haar_like_feature_coord
from skimage.feature import draw_haar_like_feature
不同類型的 Haar 類特徵描述子#
Haar 類特徵描述子有 5 種不同的類型,如下圖所示。描述子的值等於綠色和紅色區域中強度值總和的差。
images = [
np.zeros((2, 2)),
np.zeros((2, 2)),
np.zeros((3, 3)),
np.zeros((3, 3)),
np.zeros((2, 2)),
]
feature_types = ['type-2-x', 'type-2-y', 'type-3-x', 'type-3-y', 'type-4']
fig, axs = plt.subplots(3, 2)
for ax, img, feat_t in zip(np.ravel(axs), images, feature_types):
coord, _ = haar_like_feature_coord(img.shape[0], img.shape[1], feat_t)
haar_feature = draw_haar_like_feature(
img, 0, 0, img.shape[0], img.shape[1], coord, max_n_features=1, rng=0
)
ax.imshow(haar_feature)
ax.set_title(feat_t)
ax.set_xticks([])
ax.set_yticks([])
fig.suptitle('The different Haar-like feature descriptors')
plt.axis('off')
plt.show()

描述子的值等於綠色矩形和紅色矩形中強度值總和的差。紅色區域從綠色像素強度的總和中減去。實際上,Haar 類特徵將放置在影像的所有可能位置,並且將為每個位置計算特徵值。
指令碼的總執行時間: (0 分鐘 0.170 秒)