Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Add boosting tracker #20

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/tracker/tracker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ mutable struct TrackerBoosting{I <: Integer, B <: BoxROI, CS <: CurrentSampler}
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that in general you can write inequalities like this in Julia:

 if 0 < x < 1 
   do something
end

rather than

if x > 0 && x < 1
  do something
end

The former is much more readable.


TrackerBoosting(box::B, sampler::CS, num_of_classifiers::I, initial_iterations::I, num_of_features::I)
where{I <: Integer, B <: BoxROI, CS <: CurrentSampler} =
TrackerBoosting{I, B, CS}(box, sampler, num_of_classifiers, initial_iterations, num_of_features)
TrackerBoosting(box::B, sampler::CS, num_of_classifiers::I, initial_iterations::I, num_of_features::I) where{I <: Integer, B <: BoxROI, CS <: CurrentSampler} = TrackerBoosting{I, B, CS}(box, sampler, num_of_classifiers, initial_iterations, num_of_features)


#------------------
Expand Down
3 changes: 1 addition & 2 deletions src/tracker/tracker_sampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ function sample_mode_roi(sampler::CurrentSampler, box::BoxROI, sampling_region::
tr_sample = box.img[tr_block[1]:tr_block[3], tr_block[2]:tr_block[4]]
bl_sample = box.img[bl_block[1]:bl_block[3], bl_block[2]:bl_block[4]]
br_sample = box.img[br_block[1]:br_block[3], br_block[2]:br_block[4]]
samples = [(tl_sample, SVector{2, Integer}(tl_block[1:2])), (tr_sample, SVector{2, Integer}(tr_block[1:2])),
(bl_sample, SVector{2, Integer}(bl_block[1:2])), (br_sample, SVector{2, Integer}(br_block[1:2]))]
samples = [(tl_sample, SVector{2, Integer}(tl_block[1:2])) (tr_sample, SVector{2, Integer}(tr_block[1:2])) (bl_sample, SVector{2, Integer}(bl_block[1:2])) (br_sample, SVector{2, Integer}(br_block[1:2]))]

return samples
end
Expand Down
3 changes: 1 addition & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using ImageTracking
using Test


include("farneback.jl")
include("lucas_kanade.jl")
include("haar.jl")
include("visualization.jl")
include("error_evaluation.jl")

include("tracker/sample_roi.jl")
28 changes: 28 additions & 0 deletions test/tracker/sample_roi.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Images
using ImageTracking:sample_roi

@testset "ROI sampling" begin
@info "Running ROI sampling tests"
box = BoxROI(ones(300, 300), [125, 125, 175, 175])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it less error-prone, I think you need to cover the following types forbox.img:

img = ones(300, 300)
testcolors = (RGB,Gray)
testtypes =  (Float32, Float64, N0f8, N0f16)
for C in testcolors, T in testtypes
    box = BoxROI(img .|> C{T}, [125, 125, 175, 175])
    ...
end

If the function don't work for N0f8 type, manually convert it to float type in your src codes and document it (or throw an error as early as you can), otherwise, they're annoying here and there from my personal experiences.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

sampler_overlap = 0.5
search_factor = 2.0
int_img = integral_image(box.img)
currentsample = CurrentSampler(sampler_overlap, search_factor)
# positive sampling
currentsample.mode = :positive
@time samples = sample_roi(currentsample, BoxROI(int_img, box.bound))

@test size(samples) == (1, 4)
@test samples[1][1] == int_img[125:175, 125:175]

# negative sampling
currentsample.mode = :negative
@time samples = sample_roi(currentsample, BoxROI(int_img, box.bound))

@test size(samples) == (1, 4)
@test samples[1][1] == int_img[100:150, 100:150]
@test samples[2][1] == int_img[100:150, 151:201]
@test samples[3][1] == int_img[151:201, 100:150]
@test samples[4][1] == int_img[151:201, 151:201]

end;