Skip to content

Commit

Permalink
use dict for feature types for readability (closes #24)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewilliami committed Sep 28, 2020
1 parent 7dbd84f commit bce0239
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/AdaBoost.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function _create_features(
""")
end

for feature in feature_types # (feature_types are just tuples)
for feature in values(feature_types) # (feature_types are just tuples)
feature_start_width = max(min_feature_width, feature[1])
for feature_width in range(feature_start_width, stop=max_feature_width, step=feature[1])
feature_start_height = max(min_feature_height, feature[2])
Expand Down
12 changes: 6 additions & 6 deletions src/HaarLikeFeature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

include("IntegralImage.jl")

feature_types = [(1, 2), (2, 1), (3, 1), (1, 3), (2, 2)]
feature_types = Dict{String, Tuple{Integer, Integer}}("two_vertical" => (1, 2), "two_horizontal" => (2, 1), "three_horizontal" => (3, 1), "three_vertical" => (1, 3), "four" => (2, 2))

abstract type HaarFeatureAbstractType end
# abstract type AbstractHaarLikeObject <: HaarFeatureAbstractType end
Expand Down Expand Up @@ -61,29 +61,29 @@ function get_score(feature::HaarLikeObject, int_img::Array)
score = 0
faceness = 0

if feature.feature_type == feature_types[1] # two vertical
if feature.feature_type == feature_types["two_vertical"]
first = sum_region(int_img, feature.top_left, (feature.top_left[1] + feature.width, Int(round(feature.top_left[2] + feature.height / 2))))
second = sum_region(int_img, (feature.top_left[1], Int(round(feature.top_left[2] + feature.height / 2))), feature.bottom_right)
score = first - second
faceness = 1
elseif feature.feature_type == feature_types[2] # two horizontal
elseif feature.feature_type == feature_types["two_horizontal"]
first = sum_region(int_img, feature.top_left, (Int(round(feature.top_left[1] + feature.width / 2)), feature.top_left[2] + feature.height))
second = sum_region(int_img, (Int(round(feature.top_left[1] + feature.width / 2)), feature.top_left[2]), feature.bottom_right)
score = first - second
faceness = 2
elseif feature.feature_type == feature_types[3] # three horizontal
elseif feature.feature_type == feature_types["three_horizontal"]
first = sum_region(int_img, feature.top_left, (Int(round(feature.top_left[1] + feature.width / 3)), feature.top_left[2] + feature.height))
second = sum_region(int_img, (Int(round(feature.top_left[1] + feature.width / 3)), feature.top_left[2]), (Int(round(feature.top_left[1] + 2 * feature.width / 3)), feature.top_left[2] + feature.height))
third = sum_region(int_img, (Int(round(feature.top_left[1] + 2 * feature.width / 3)), feature.top_left[2]), feature.bottom_right)
score = first - second + third
faceness = 3
elseif feature.feature_type == feature_types[4] # three vertical
elseif feature.feature_type == feature_types["three_vertical"]
first = sum_region(int_img, feature.top_left, (feature.bottom_right[1], Int(round(feature.top_left[2] + feature.height / 3))))
second = sum_region(int_img, (feature.top_left[1], Int(round(feature.top_left[2] + feature.height / 3))), (feature.bottom_right[1], Int(round(feature.top_left[2] + 2 * feature.height / 3))))
third = sum_region(int_img, (feature.top_left[1], Int(round(feature.top_left[2] + 2 * feature.height / 3))), feature.bottom_right)
score = first - second + third
faceness = 4
elseif feature.feature_type == feature_types[5] # four
elseif feature.feature_type == feature_types["four"]
# top left area
first = sum_region(int_img, feature.top_left, (Int(round(feature.top_left[1] + feature.width / 2)), Int(round(feature.top_left[2] + feature.height / 2))))
# top right area
Expand Down
20 changes: 10 additions & 10 deletions src/Utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function reconstruct(classifiers::AbstractArray, img_size::Tuple)
for c in classifiers
# map polarity: -1 -> 0, 1 -> 1
polarity = ((1 + c.polarity)^2)/4
if c.feature_type == feature_types[1] # two vertical
if c.feature_type == feature_types["two_vertical"]
for x in 1:c.width
sign = polarity
for y in 1:c.height
Expand All @@ -231,7 +231,7 @@ function reconstruct(classifiers::AbstractArray, img_size::Tuple)
image[c.top_left[2] + y, c.top_left[1] + x] += 1 * sign * c.weight
end
end
elseif c.feature_type == feature_types[2] # two horizontal
elseif c.feature_type == feature_types["two_horizontal"]
sign = polarity
for x in 1:c.width
if x >= c.width/2
Expand All @@ -241,7 +241,7 @@ function reconstruct(classifiers::AbstractArray, img_size::Tuple)
image[c.top_left[1] + x, c.top_left[2] + y] += 1 * sign * c.weight
end
end
elseif c.feature_type == feature_types[3] # three horizontal
elseif c.feature_type == feature_types["three_horizontal"]
sign = polarity
for x in 1:c.width
if iszero(mod(x, c.width/3))
Expand All @@ -251,7 +251,7 @@ function reconstruct(classifiers::AbstractArray, img_size::Tuple)
image[c.top_left[1] + x, c.top_left[2] + y] += 1 * sign * c.weight
end
end
elseif c.feature_type == feature_types[4] # three vertical
elseif c.feature_type == feature_types["three_vertical"]
for x in 1:c.width
sign = polarity
for y in 1:c.height
Expand All @@ -261,7 +261,7 @@ function reconstruct(classifiers::AbstractArray, img_size::Tuple)
image[c.top_left[1] + x, c.top_left[2] + y] += 1 * sign * c.weight
end
end
elseif c.feature_type == feature_types[5] # four
elseif c.feature_type == feature_types["four"]
sign = polarity
for x in 1:c.width
if iszero(mod(x, c.width/2))
Expand Down Expand Up @@ -435,7 +435,7 @@ function generate_validation_image(image_path::AbstractString, classifiers::Abst
for c in classifiers
# map polarity: -1 -> 0, 1 -> 1
polarity = ((1 + c.polarity)^2)/4
if c.feature_type == feature_types[1] # two vertical
if c.feature_type == feature_types["two_vertical"]
for x in 1:c.width
sign = polarity
for y in 1:c.height
Expand All @@ -445,7 +445,7 @@ function generate_validation_image(image_path::AbstractString, classifiers::Abst
boxes[c.top_left[2] + y, c.top_left[1] + x] += 1 * sign * c.weight
end
end
elseif c.feature_type == feature_types[2] # two horizontal
elseif c.feature_type == feature_types["two_horizontal"]
sign = polarity
for x in 1:c.width
if x >= c.width/2
Expand All @@ -455,7 +455,7 @@ function generate_validation_image(image_path::AbstractString, classifiers::Abst
boxes[c.top_left[1] + x, c.top_left[2] + y] += 1 * sign * c.weight
end
end
elseif c.feature_type == feature_types[3] # three horizontal
elseif c.feature_type == feature_types["three_horizontal"]
sign = polarity
for x in 1:c.width
if iszero(mod(x, c.width/3))
Expand All @@ -465,7 +465,7 @@ function generate_validation_image(image_path::AbstractString, classifiers::Abst
boxes[c.top_left[1] + x, c.top_left[2] + y] += 1 * sign * c.weight
end
end
elseif c.feature_type == feature_types[4] # three vertical
elseif c.feature_type == feature_types["three_vertical"]
for x in 1:c.width
sign = polarity
for y in 1:c.height
Expand All @@ -475,7 +475,7 @@ function generate_validation_image(image_path::AbstractString, classifiers::Abst
boxes[c.top_left[1] + x, c.top_left[2] + y] += 1 * sign * c.weight
end
end
elseif c.feature_type == feature_types[5] # four
elseif c.feature_type == feature_types["four"]
sign = polarity
for x in 1:c.width
if iszero(mod(x, c.width/2))
Expand Down

0 comments on commit bce0239

Please sign in to comment.