Skip to content

Commit 20d709f

Browse files
authored
Merge pull request #82 from JuliaImages/vs/features2d-wrappers
Wrap features2d (2/2): generated wrappers + tests (closes #51)
2 parents 52c3c7f + 96351c1 commit 20d709f

2 files changed

Lines changed: 23 additions & 37 deletions

File tree

src/cv_manual_wrap.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ function CascadeClassifier(filename::String)
2828
end
2929

3030

31-
function detect(cobj::cv_Ptr{T}, image::InputArray, mask::InputArray) where {T <: Feature2D}
32-
return cpp_to_julia(jlopencv_cv_cv_Feature2D_cv_Feature2D_detect(julia_to_cpp(cobj),julia_to_cpp(image),julia_to_cpp(mask)))
33-
end
34-
detect(cobj::cv_Ptr{T}, image::InputArray; mask::InputArray = (CxxMat())) where {T <: Feature2D} = detect(cobj, image, mask)
35-
36-
3731
function detectMultiScale(cobj::CascadeClassifier, image::InputArray, scaleFactor::Float64, minNeighbors::Int32, flags::Int32, minSize::Size{Int32}, maxSize::Size{Int32})
3832
return cpp_to_julia(jlopencv_cv_cv_CascadeClassifier_cv_CascadeClassifier_detectMultiScale(julia_to_cpp(cobj),julia_to_cpp(image),julia_to_cpp(scaleFactor),julia_to_cpp(minNeighbors),julia_to_cpp(flags),julia_to_cpp(minSize),julia_to_cpp(maxSize)))
3933
end
@@ -43,11 +37,6 @@ function empty(cobj::CascadeClassifier)
4337
return cpp_to_julia(jlopencv_cv_cv_CascadeClassifier_cv_CascadeClassifier_empty(julia_to_cpp(cobj)))
4438
end
4539

46-
function SimpleBlobDetector_create(parameters::SimpleBlobDetector_Params)
47-
return cpp_to_julia(jlopencv_cv_cv_SimpleBlobDetector_create(julia_to_cpp(parameters)))
48-
end
49-
SimpleBlobDetector_create(; parameters::SimpleBlobDetector_Params = (SimpleBlobDetector_Params())) = SimpleBlobDetector_create(parameters)
50-
5140
## Convenience: mirror Python's `cv.VideoWriter_fourcc(*"h264")`. Issue #31.
5241
function VideoWriter_fourcc(s::AbstractString)
5342
length(s) == 4 ||

test/test_feature2d.jl

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
# test simple blob detector
2-
# TODO: the keypoint distance assertion below is intermittently wrong across
3-
# platforms, and on Julia 1.11 + Windows `OpenCV.detect` itself hits a
4-
# stack-overflow in the artifact's `julia_to_cpp` stride fallback. Disable the
5-
# whole block until both issues are addressed.
6-
#
7-
# img_gray = OpenCV.imread(joinpath(test_dir, "shared", "pic1.png"), OpenCV.IMREAD_GRAYSCALE)
8-
#
9-
# detector = OpenCV.SimpleBlobDetector_create()
10-
#
11-
# # Compare centers of keypoints and se how many of them match,
12-
# kps = OpenCV.detect(detector, img_gray)
13-
#
14-
# kps_expect = [OpenCV.Point{Float32}(174.9114f0, 227.75146f0),OpenCV.Point{Float32}(106.925545f0, 179.5765f0)]
15-
# for kp in kps
16-
# closest_match = 100000
17-
# for kpe in kps_expect
18-
# dx = kpe.x - kp.pt.x
19-
# dy = kpe.y - kp.pt.y
20-
# if sqrt(dx*dx+dy*dy) < closest_match
21-
# closest_match = sqrt(dx*dx+dy*dy)
22-
# end
23-
# end
24-
#
25-
# @test closest_match < 10
26-
# end
1+
@testset "features2d" begin
2+
img_gray = OpenCV.imread(joinpath(test_dir, "shared", "pic1.png"), OpenCV.IMREAD_GRAYSCALE)
3+
4+
@testset "ORB detect+compute+match" begin
5+
orb = OpenCV.ORB_create()
6+
kps = OpenCV.detect(orb, img_gray)
7+
@test length(kps) > 0
8+
kps2, desc = OpenCV.compute(orb, img_gray, kps)
9+
@test length(kps2) == length(kps)
10+
@test size(desc, 1) == length(kps)
11+
@test size(desc, 2) == OpenCV.descriptorSize(orb)
12+
13+
bf = OpenCV.BFMatcher_create(OpenCV.NORM_HAMMING, true)
14+
matches = OpenCV.match(bf, desc, desc)
15+
@test length(matches) == length(kps)
16+
end
17+
18+
@testset "SimpleBlobDetector" begin
19+
detector = OpenCV.SimpleBlobDetector_create()
20+
kps = OpenCV.detect(detector, img_gray)
21+
@test length(kps) > 0
22+
end
23+
end

0 commit comments

Comments
 (0)