@@ -11,26 +11,71 @@ include("IntegralImage.jl")
11
11
# FeatureType = enum(TWO_VERTICAL=(1, 2), TWO_HORIZONTAL=(2, 1), THREE_HORIZONTAL=(3, 1), THREE_VERTICAL=(1, 3), FOUR=(2, 2))
12
12
# FeatureTypes = Array(FeatureType.TWO_VERTICAL, FeatureType.TWO_HORIZONTAL, FeatureType.THREE_VERTICAL, FeatureType.THREE_HORIZONTAL, FeatureType.FOUR)
13
13
14
- FeatureType = Dict{String, AbstractArray }(" two_vertical" => (1, 2), " two_horizontal" => (2, 1), " three_horizontal" => (3,1), " three_vertical" => (1,3), " four" => (2, 2))
14
+ FeatureType = Dict{String, Tuple{Int64,Int64} }(" two_vertical" => (1, 2), " two_horizontal" => (2, 1), " three_horizontal" => (3,1), " three_vertical" => (1,3), " four" => (2, 2))
15
15
FeatureTypes = [FeatureType[" two_vertical" ], FeatureType[" two_horizontal" ], FeatureType[" three_horizontal" ], FeatureType[" three_vertical" ], FeatureType[" four" ]]
16
16
17
17
18
- abstract type HaarType end
18
+ abstract type HaarObject end
19
+ #
20
+ #
21
+ # struct HaarLikeFeature <: HaarType
22
+ # feature_type::Any
23
+ # position::Array
24
+ # topLeft::Array
25
+ # bottomRight::Array
26
+ # width::Int64
27
+ # height::Int64
28
+ # threshold::Float64
29
+ # polarity::Int64
30
+ # weight::Float64
31
+ #
32
+ # # constructor; equivalent of __init__ method within class
33
+ # function HaarLikeFeature(feature_type::Any, position::Array, width::Int64, height::Int64, threshold::Float64, polarity::Int64, weight::Float64)
34
+ # topLeft = position
35
+ # bottomRight = (position[1] + width, position[2] + height)
36
+ # weight = 1
37
+ # new(feature_type, topLeft, bottomRight, width, height, threshold, polarity)
38
+ # end # end constructor
39
+ # end # end structure
40
+ #
41
+ #
42
+ # #
43
+ # function getScore(self::HaarLikeFeature, intImg::AbstractArray)
44
+ # """
45
+ # Get score for given integral image array.
46
+ # :param int_img: Integral image array
47
+ # :type int_img: numpy.ndarray
48
+ # :return: Score for given feature
49
+ # :rtype: float
50
+ # """
51
+ # # set instance of score outside of ifs
52
+ # score = 0
53
+ #
54
+ # if self.feature_type == FeatureType["two_vertical"]
55
+ # first = sumRegion(intImg, self.top_left, (self.top_left[1] + self.width, Int(self.top_left[2] + self.height / 2)))
56
+ # second = sumRegion(int_img, (self.top_left[1], Int(self.top_left[2] + self.height / 2)), self.bottom_right)
57
+ # score = first - second
58
+ # end
59
+ # return score
60
+ #
61
+ # end # end getScore function
19
62
20
63
21
- struct HaarLikeFeature < : HaarType
22
- feature_type::Any
23
- position::Array
24
- topLeft::Array
25
- bottomRight::Array
64
+ abstract type HaarFeatureType end
65
+
66
+ # make structure
67
+ struct HaarLikeFeature < : HaarFeatureType#struct HaarLikeFeature{T} < : HaarObject where {T < : HaarFeatureType}
68
+ position::Tuple{Int64, Int64}
69
+ topLeft::Tuple{Int64, Int64}
70
+ bottomRight::Tuple{Int64, Int64}
26
71
width::Int64
27
72
height::Int64
28
73
threshold::Float64
29
74
polarity::Int64
30
75
weight::Float64
31
76
32
77
# constructor; equivalent of __init__ method within class
33
- function HaarLikeFeature(feature_type::Any, position::Array , width::Int64, height::Int64, threshold::Float64, polarity::Int64, weight::Float64)
78
+ function HaarLikeFeature(position::Tuple{Int64, Int64} , width::Int64, height::Int64, threshold::Float64, polarity::Int64, weight::Float64)
34
79
topLeft = position
35
80
bottomRight = (position[1] + width, position[2] + height)
36
81
weight = 1
@@ -39,85 +84,71 @@ struct HaarLikeFeature <: HaarType
39
84
end # end structure
40
85
41
86
42
- #
43
- function getScore(self::HaarLikeFeature, intImg::AbstractArray)
44
- " " "
45
- Get score for given integral image array.
46
- :param int_img: Integral image array
47
- :type int_img: numpy.ndarray
48
- :return: Score for given feature
49
- :rtype: float
50
- " " "
51
- # set instance of score outside of ifs
52
- score = 0
53
-
54
- if self.feature_type == FeatureType[" two_vertical" ]
55
- first = sumRegion(intImg, self.top_left, (self.top_left[1] + self.width, Int(self.top_left[2] + self.height / 2)))
56
- second = sumRegion(int_img, (self.top_left[1], Int(self.top_left[2] + self.height / 2)), self.bottom_right)
57
- score = first - second
58
- end
59
- return score
60
-
61
- end # end getScore function
62
-
87
+ # define the various Haar like feature types
88
+ struct HaarFeatureTwoVertical < : HaarFeatureType end
89
+ struct HaarFeatureTwoHorizontal < : HaarFeatureType end
90
+ struct HaarFeatureThreeHorizontal < : HaarFeatureType end
91
+ struct HaarFeatureThreeVertical < : HaarFeatureType end
92
+ struct HaarFeatureFour < : HaarFeatureType end
63
93
64
94
65
- imgArr = getImageMatrix ()
66
- integralImageArr = toIntegralImage(imgArr)
95
+ # HaarFeatureTwoVertical = (1, 2)
67
96
68
- # println(integralImageArr)
69
97
70
- output = getScore(integralImageArr)
98
+ # construct integral image
99
+ intImg = toIntegralImage(getImageMatrix ())
71
100
72
- println(output)
101
+ function score(::HaarFeatureTwoVertical, self::HaarLikeFeature)
102
+ first = sumRegion(intImg, self.top_left, (self.top_left[1] + self.width, Int(self.top_left[2] + self.height / 2)))
103
+ second = sumRegion(intImg, (self.top_left[1], Int(self.top_left[2] + self.height / 2)), self.bottom_right)
104
+ score = first - second
105
+ return score
106
+ end
73
107
74
- # x = new HaarLikeFeature()
108
+ function score(::HaarFeatureTwoHorizontal, self::HaarLikeFeature)
109
+ first = sumRegion(intImg, self.top_left, (int(self.top_left[1] + self.width / 3), self.top_left[2] + self.height))
110
+ second = sumRegion(intImg, (Int(self.top_left[1] + self.width / 3), self.top_left[1]), (Int(self.top_left[1] + 2 * self.width / 3), self.top_left[2] + self.height))
111
+ third = sumRegion(intImg, (Int(self.top_left[1] + 2 * self.width / 3), self.top_left[2]), self.bottom_right)
112
+ score = first - second + third
113
+ return score
114
+ end
75
115
76
- # function Base.show(io::IO, gs::HaarLikeFeature)
77
- # println(io, getScore(gs))
78
- # end
79
- #
80
- # show(integralImageArr)
116
+ function score(::HaarFeatureThreeHorizontal, self::HaarLikeFeature)
117
+ first = sumRegion(intImg, self.top_left, (Int(self.top_left[1] + self.width / 3), self.top_left[2] + self.height))
118
+ second = sumRegion(intImg, (Int(self.top_left[1] + self.width / 3), self.top_left[2]), (Int(self.top_left[1] + 2 * self.width / 3), self.top_left[2] + self.height))
119
+ third = sumRegion(intImg, (Int(self.top_left[1] + 2 * self.width / 3), self.top_left[2]), self.bottom_right)
120
+ score = first - second + third
121
+ return score
122
+ end
81
123
82
- # def _get_feature_vote(feature, image):
83
- # return feature.get_vote(image)
124
+ function score(::HaarFeatureThreeVertical, self::HaarLikeFeature)
125
+ first = sumRegion(intImg, self.top_left, (self.bottom_right[1], Int(self.top_left[2] + self.height / 3)))
126
+ second = sumRegion(intImg, (self.top_left[1], Int(self.top_left[2] + self.height / 3)), (self.bottom_right[1], Int(self.top_left[2] + 2 * self.height / 3)))
127
+ third = sumRegion(intImg, (self.top_left[1], Int(self.top_left[2] + 2 * self.height / 3)), self.bottom_right)
128
+ score = first - second + third
129
+ return score
130
+ end
84
131
85
- # x.getScore(integralImageArr)
132
+ function score(::HaarFeatureFour, self::HaarLikeFeature)
133
+ # top left area
134
+ first = sumRegion(intImg, self.top_left, (Int(self.top_left[1] + self.width / 2), Int(self.top_left[2] + self.height / 2)))
135
+ # top right area
136
+ second = sumRegion(intImg, (Int(self.top_left[1] + self.width / 2), self.top_left[2]), (self.bottom_right[1], Int(self.top_left[2] + self.height / 2)))
137
+ # bottom left area
138
+ third = sumRegion(intImg, (self.top_left[1], Int(self.top_left[2] + self.height / 2)), (Int(self.top_left[1] + self.width / 2), self.bottom_right[2]))
139
+ # bottom right area
140
+ fourth = sumRegion(intImg, (Int(self.top_left[1] + self.width / 2), int(self.top_left[2] + self.height / 2)), self.bottom_right)
141
+ score = first - second - third + fourth
142
+ return score
143
+ end
86
144
87
- abstract type HaarFeatureType end
88
145
89
- struct HaarLikeFeature < : HaarType
90
- position::Array{Int64, 2}
91
- topLeft::Array{Int64, 2}
92
- bottomRight::Array{Int64, 2}
93
- width::Int64
94
- height::Int64
95
- threshold::Float64
96
- polarity::Int64
97
- weight::Float64
98
-
99
- # constructor; equivalent of __init__ method within class
100
- function HaarLikeFeature(position::Array, width::Int64, height::Int64, threshold::Float64, polarity::Int64, weight::Float64)
101
- topLeft = position
102
- bottomRight = (position[1] + width, position[2] + height)
103
- weight = 1
104
- new(feature_type, topLeft, bottomRight, width, height, threshold, polarity)
105
- end # end constructor
106
- end # end structure
107
146
147
+ # imgArr = getImageMatrix()
148
+ # integralImageArr = toIntegralImage(imgArr)
108
149
109
- struct HaarFeatureTwoVertical < : HaarFeatureType end
110
- struct HaarFeatureTwoHorizontal < : HaarFeatureType end
150
+ # println(integralImageArr)
111
151
112
- function score(::HaarFeatureTwoVertical, self::HaarLikeFeature)
113
- first = ii.sum_region(int_img, self.top_left, (self.top_left[0] + self.width, int(self.top_left[1] + self.height / 2)))
114
- second = ii.sum_region(int_img, (self.top_left[0], int(self.top_left[1] + self.height / 2)), self.bottom_right)
115
- return first - second
116
- end
152
+ output = score(intImg)
117
153
118
- function score(::HaarFeatureTwoHoritontal, self::HaarLikeFeature)
119
- first = ii.sum_region(int_img, self.top_left, (int(self.top_left[0] + self.width / 3), self.top_left[1] + self.height))
120
- second = ii.sum_region(int_img, (int(self.top_left[0] + self.width / 3), self.top_left[1]), (int(self.top_left[0] + 2 * self.width / 3), self.top_left[1] + self.height))
121
- third = ii.sum_region(int_img, (int(self.top_left[0] + 2 * self.width / 3), self.top_left[1]), self.bottom_right)
122
- return first - second + third
123
- end
154
+ println(output)
0 commit comments