@@ -18,6 +18,16 @@ abstract type HaarFeatureAbstractType end
1818 mutable struct HaarLikeObject{I <: Integer, F <: AbstractFloat}
1919
2020 Struct representing a Haar-like feature.
21+
22+ feature_type::Tuple{I, I}
23+ position::Tuple{I, I}
24+ top_left::Tuple{I, I}
25+ bottom_right::Tuple{I, I}
26+ width::I
27+ height::I
28+ threshold::I
29+ polarity::I
30+ weight::F
2131" " "
2232mutable struct HaarLikeObject{I < : Integer, F < : AbstractFloat} < : HaarFeatureAbstractType
2333 # parametric struct to store the ints and floats efficiently
@@ -32,6 +42,16 @@ mutable struct HaarLikeObject{I <: Integer, F <: AbstractFloat} <: HaarFeatureAb
3242 weight::F
3343end # end structure
3444
45+ " " "
46+ HaarLikeObject(
47+ feature_type::Tuple{Integer, Integer},
48+ position::Tuple{Integer, Integer},
49+ width::Integer,
50+ height::Integer,
51+ threshold::Integer,
52+ polarity::Integer
53+ ) -> HaarLikeObject
54+ " " "
3555function HaarLikeObject(
3656 feature_type::Tuple{Integer, Integer},
3757 position::Tuple{Integer, Integer},
5979" " "
6080 get_score(feature::HaarLikeObject, int_img::Array) -> Tuple{Number, Number}
6181
62- Get score for given integral image array.
82+ Get score for given integral image array. This is the feature cascade.
6383
6484# Arguments
6585
@@ -70,7 +90,7 @@ Get score for given integral image array.
7090
7191- ` score::Number` : Score for given feature
7292" " "
73- function get_score(feature::HaarLikeObject{I,F}, int_img::Array) where {I, F}
93+ function get_score(feature::HaarLikeObject{I, F}, int_img::Array) where {I, F}
7494 score = zero(I)
7595 faceness = zero(I)
7696 _2f = F(2)
@@ -79,36 +99,36 @@ function get_score(feature::HaarLikeObject{I,F}, int_img::Array) where {I, F}
7999 _one_third = F(1.0 / 3.0)
80100
81101 if feature.feature_type == feature_types.two_vertical
82- _first = sum_region(int_img, feature.top_left, (first(feature.top_left) + feature.width, I( round(last(feature.top_left) + feature.height / 2) )))
83- second = sum_region(int_img, (first(feature.top_left), I( round(last(feature.top_left) + feature.height / 2) )), feature.bottom_right)
102+ _first = sum_region(int_img, feature.top_left, (first(feature.top_left) + feature.width, round(I, last(feature.top_left) + feature.height / 2)))
103+ second = sum_region(int_img, (first(feature.top_left), round(I, last(feature.top_left) + feature.height / 2)), feature.bottom_right)
84104 score = _first - second
85105 faceness = I(1)
86106 elseif feature.feature_type == feature_types.two_horizontal
87- _first = sum_region(int_img, feature.top_left, (I( round(first(feature.top_left) + feature.width / 2) ), last(feature.top_left) + feature.height))
88- second = sum_region(int_img, (I( round(first(feature.top_left) + feature.width / 2) ), last(feature.top_left)), feature.bottom_right)
107+ _first = sum_region(int_img, feature.top_left, (round(I, first(feature.top_left) + feature.width / 2), last(feature.top_left) + feature.height))
108+ second = sum_region(int_img, (round(I, first(feature.top_left) + feature.width / 2), last(feature.top_left)), feature.bottom_right)
89109 score = _first - second
90110 faceness = I(2)
91111 elseif feature.feature_type == feature_types.three_horizontal
92- _first = sum_region(int_img, feature.top_left, (I( round(first(feature.top_left) + feature.width / 3) ), last(feature.top_left) + feature.height))
93- second = sum_region(int_img, (I( round(first(feature.top_left) + feature.width / 3)) , last(feature.top_left)), (I( round(first(feature.top_left) + 2 * feature.width / 3) ), last(feature.top_left) + feature.height))
94- third = sum_region(int_img, (I( round(first(feature.top_left) + 2 * feature.width / 3) ), last(feature.top_left)), feature.bottom_right)
112+ _first = sum_region(int_img, feature.top_left, (round(I, first(feature.top_left) + feature.width / 3), last(feature.top_left) + feature.height))
113+ second = sum_region(int_img, (round(I, first(feature.top_left) + feature.width / 3), last(feature.top_left)), (round(I, first(feature.top_left) + 2 * feature.width / 3), last(feature.top_left) + feature.height))
114+ third = sum_region(int_img, (round(I, first(feature.top_left) + 2 * feature.width / 3), last(feature.top_left)), feature.bottom_right)
95115 score = _first - second + third
96116 faceness = I(3)
97117 elseif feature.feature_type == feature_types.three_vertical
98- _first = sum_region(int_img, feature.top_left, (first(feature.bottom_right), I( round(last(feature.top_left) + feature.height / 3) )))
99- second = sum_region(int_img, (first(feature.top_left), I( round(last(feature.top_left) + feature.height / 3))) , (first(feature.bottom_right), I( round(last(feature.top_left) + 2 * feature.height / 3) )))
100- third = sum_region(int_img, (first(feature.top_left), I( round(last(feature.top_left) + 2 * feature.height / 3) )), feature.bottom_right)
118+ _first = sum_region(int_img, feature.top_left, (first(feature.bottom_right), round(I, last(feature.top_left) + feature.height / 3)))
119+ second = sum_region(int_img, (first(feature.top_left), round(I, last(feature.top_left) + feature.height / 3)), (first(feature.bottom_right), round(I, last(feature.top_left) + 2 * feature.height / 3)))
120+ third = sum_region(int_img, (first(feature.top_left), round(I, last(feature.top_left) + 2 * feature.height / 3)), feature.bottom_right)
101121 score = _first - second + third
102122 faceness = I(4)
103123 elseif feature.feature_type == feature_types.four
104124 # top left area
105- _first = sum_region(int_img, feature.top_left, (I( round(first(feature.top_left) + feature.width / 2)), I( round(last(feature.top_left) + feature.height / 2) )))
125+ _first = sum_region(int_img, feature.top_left, (round(I, first(feature.top_left) + feature.width / 2), round(I, last(feature.top_left) + feature.height / 2)))
106126 # top right area
107- second = sum_region(int_img, (I( round(first(feature.top_left) + feature.width / 2)) , last(feature.top_left)), (first(feature.bottom_right), I( round(last(feature.top_left) + feature.height / 2) )))
127+ second = sum_region(int_img, (round(I, first(feature.top_left) + feature.width / 2), last(feature.top_left)), (first(feature.bottom_right), round(I, last(feature.top_left) + feature.height / 2)))
108128 # bottom left area
109- third = sum_region(int_img, (first(feature.top_left), I( round(last(feature.top_left) + feature.height / 2))) , (I( round(first(feature.top_left) + feature.width / 2) ), last(feature.bottom_right)))
129+ third = sum_region(int_img, (first(feature.top_left), round(I, last(feature.top_left) + feature.height / 2)), (round(I, first(feature.top_left) + feature.width / 2), last(feature.bottom_right)))
110130 # bottom right area
111- fourth = sum_region(int_img, (I( round(first(feature.top_left) + feature.width / 2)), I( round(last(feature.top_left) + feature.height / 2) )), feature.bottom_right)
131+ fourth = sum_region(int_img, (round(I, first(feature.top_left) + feature.width / 2), round(I, last(feature.top_left) + feature.height / 2)), feature.bottom_right)
112132 score = _first - second - third + fourth
113133 faceness = I(5)
114134 end
@@ -133,6 +153,9 @@ Get vote of this feature for given integral image.
133153 -1 otherwise
134154" " "
135155function get_vote(feature::HaarLikeObject, int_img::AbstractArray)
136- score = first(get_score(feature, int_img)) # we only care about score here
137- return (feature.weight * score) < (feature.polarity * feature.threshold) ? one(Int8) : -one(Int8)
156+ score = first(get_score(feature, int_img)) # we only care about score here, not faceness
157+ # return (feature.weight * score) < (feature.polarity * feature.threshold) ? one(Int8) : -one(Int8)
158+ # return feature.weight * (score < feature.polarity * feature.threshold ? one(Int8) : -one(Int8))
159+ return score < feature.polarity * feature.threshold ? feature.weight : -feature.weight
160+ # self.weight * (1 if score < self.polarity * self.threshold else -1)
138161end
0 commit comments