@@ -11,26 +11,71 @@ include("IntegralImage.jl")
1111# FeatureType = enum(TWO_VERTICAL=(1, 2), TWO_HORIZONTAL=(2, 1), THREE_HORIZONTAL=(3, 1), THREE_VERTICAL=(1, 3), FOUR=(2, 2))
1212# FeatureTypes = Array(FeatureType.TWO_VERTICAL, FeatureType.TWO_HORIZONTAL, FeatureType.THREE_VERTICAL, FeatureType.THREE_HORIZONTAL, FeatureType.FOUR)
1313
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))
1515FeatureTypes = [FeatureType[" two_vertical" ], FeatureType[" two_horizontal" ], FeatureType[" three_horizontal" ], FeatureType[" three_vertical" ], FeatureType[" four" ]]
1616
1717
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
1962
2063
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}
2671 width::Int64
2772 height::Int64
2873 threshold::Float64
2974 polarity::Int64
3075 weight::Float64
3176
3277 # 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)
3479 topLeft = position
3580 bottomRight = (position[1] + width, position[2] + height)
3681 weight = 1
@@ -39,85 +84,71 @@ struct HaarLikeFeature <: HaarType
3984end # end structure
4085
4186
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
6393
6494
65- imgArr = getImageMatrix ()
66- integralImageArr = toIntegralImage(imgArr)
95+ # HaarFeatureTwoVertical = (1, 2)
6796
68- # println(integralImageArr)
6997
70- output = getScore(integralImageArr)
98+ # construct integral image
99+ intImg = toIntegralImage(getImageMatrix ())
71100
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
73107
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
75115
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
81123
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
84131
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
86144
87- abstract type HaarFeatureType end
88145
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
107146
147+ # imgArr = getImageMatrix()
148+ # integralImageArr = toIntegralImage(imgArr)
108149
109- struct HaarFeatureTwoVertical < : HaarFeatureType end
110- struct HaarFeatureTwoHorizontal < : HaarFeatureType end
150+ # println(integralImageArr)
111151
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)
117153
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