1

我们如何使用 scikit-image 函数haar_like_feature计算所有类型的所有类 Haar 特征?这是我尝试过的(一个计算类型 2x 的所有特征的简单示例):

from skimage.feature import haar_like_feature
from skimage.transform import integral_image

img = np.array([[1,  2],
                [1,  3]])

ii = integral_image(img)

features = haar_like_feature(ii, 0, 0, ii.shape[1], ii.shape[0], 'type-2-x')

print(features)
[1, 2]

但是我希望得到[1, 2, 3],因为我们还应该考虑覆盖整个图像的矩形特征,从而产生特征值(2 + 3) - (1 + 1) = 3

我还查看了 Viola-Jones 论文,它们具有以下几个特征:

type-2-x: 43200
type-2-y: 43200
type-3-x: 27600
type-3-y: 27600
type-4: 20736

total: 162336

(来源:Viola-Jones 人脸检测算法分析

但是产生的特征数量skimage.feature.haar_like_feature是不同的:

img = np.random.randint(0, 256, (24,24))
ii = integral_image(img)

total = 0
for feature_type in ['type-2-x', 'type-2-y', 'type-3-x', 'type-3-y', 'type-4']:
    features = haar_like_feature(ii, 0, 0, ii.shape[1], ii.shape[0], feature_type)
    print(f"{feature_type}: {len(features)}")
    total += len(features)
print("\ntotal:", total)

type-2-x: 43056
type-2-y: 43056
type-3-x: 27508
type-3-y: 27508
type-4: 20736

total: 161864

因此,这个计算中似乎缺少 472 个特征。我做错了吗?我应该将哪些参数传递给函数haar_like_feature()以获取所有功能?

更新:函数https://github.com/scikit-image/scikit-image/issues/4818的实现似乎存在错误haar_like_feature

4

1 回答 1

-3

在这里,只想分享:

从这里开始:img = np.array([[1, 2], [1, 3]])

to : img = np.random.randint(0, 256, (12,12))

尝试将 np.array() 的输入大小或图像大小..增加到例如 12x12。

于 2020-09-11T07:31:06.433 回答