vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
set(JULIA_TEST_PROXY ${CMAKE_CURRENT_BINARY_DIR}/test.proxy)
|
||||
file(REMOVE ${JULIA_TEST_PROXY})
|
||||
|
||||
# generate
|
||||
# call the python executable to generate the julia gateways
|
||||
add_custom_command(
|
||||
OUTPUT ${JULIA_TEST_PROXY}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/testsuite.jl ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/test_feature2d.jl ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/test_objdetect.jl ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/test_imgproc.jl ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/test_mat.jl ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/test_dnn.jl ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E touch ${JULIA_TEST_PROXY}
|
||||
COMMENT "Building Julia tests"
|
||||
)
|
||||
|
||||
# targets# opencv_julia_sources --> opencv_julia
|
||||
|
||||
add_custom_target(opencv_test_julia ALL DEPENDS ${JULIA_TEST_PROXY})
|
||||
add_dependencies(opencv_test_julia ${the_module})
|
||||
|
||||
message(STATUS "Placing Julia tests in ${CMAKE_CURRENT_BINARY_DIR}")
|
||||
# run the julia test suite
|
||||
add_test(NAME opencv_test_julia
|
||||
COMMAND ${Julia_EXECUTABLE} "testsuite.jl"
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
@@ -0,0 +1,32 @@
|
||||
function IOU(boxA, boxB)
|
||||
xA = max(boxA[1], boxB[1])
|
||||
yA = max(boxA[2], boxB[2])
|
||||
xB = min(boxA[3], boxB[3])
|
||||
yB = min(boxA[4], boxB[4])
|
||||
interArea = max(0, xB - xA + 1) * max(0, yB - yA + 1)
|
||||
boxAArea = (boxA[3] - boxA[1] + 1) * (boxA[4] - boxA[2] + 1)
|
||||
boxBArea = (boxB[3] - boxB[1] + 1) * (boxB[4] - boxB[2] + 1)
|
||||
iou = interArea / float(boxAArea + boxBArea - interArea)
|
||||
return iou
|
||||
end
|
||||
|
||||
const cv = OpenCV
|
||||
net = cv.dnn.DetectionModel(joinpath(ENV["OPENCV_TEST_DATA_PATH"], "dnn", "opencv_face_detector.pbtxt"),joinpath(ENV["OPENCV_TEST_DATA_PATH"], "dnn", "opencv_face_detector_uint8.pb"))
|
||||
size0 = 300
|
||||
|
||||
cv.dnn.setPreferableTarget(net, cv.dnn.DNN_TARGET_CPU)
|
||||
cv.dnn.setInputMean(net, (104, 177, 123))
|
||||
cv.dnn.setInputScale(net, 1.)
|
||||
cv.dnn.setInputSize(net, size0, size0)
|
||||
|
||||
|
||||
img = OpenCV.imread(joinpath(test_dir, "cascadeandhog", "images", "mona-lisa.png"))
|
||||
|
||||
classIds, confidences, boxes = cv.dnn.detect(net, img, confThreshold=0.5)
|
||||
|
||||
box = (boxes[1].x, boxes[1].y, boxes[1].x+boxes[1].width, boxes[1].y+boxes[1].height)
|
||||
expected_rect = (185,101,129+185,169+101)
|
||||
|
||||
@test IOU(box, expected_rect) > 0.8
|
||||
|
||||
print("dnn test passed\n")
|
||||
@@ -0,0 +1,23 @@
|
||||
# test simple blob detector
|
||||
img_gray = OpenCV.imread(joinpath(test_dir, "shared", "pic1.png"), OpenCV.IMREAD_GRAYSCALE)
|
||||
|
||||
detector = OpenCV.SimpleBlobDetector_create()
|
||||
|
||||
# Compare centers of keypoints and se how many of them match,
|
||||
kps = OpenCV.detect(detector, img_gray)
|
||||
|
||||
kps_expect = [OpenCV.Point{Float32}(174.9114f0, 227.75146f0),OpenCV.Point{Float32}(106.925545f0, 179.5765f0)]
|
||||
for kp in kps
|
||||
closest_match = 100000
|
||||
for kpe in kps_expect
|
||||
dx = kpe.x - kp.pt.x
|
||||
dy = kpe.y - kp.pt.y
|
||||
if sqrt(dx*dx+dy*dy) < closest_match
|
||||
closest_match = sqrt(dx*dx+dy*dy)
|
||||
end
|
||||
end
|
||||
|
||||
@test closest_match < 10
|
||||
end
|
||||
|
||||
println("feature2d test passed")
|
||||
@@ -0,0 +1,28 @@
|
||||
# Create a random image
|
||||
img = rand(UInt8 , 3, 500, 500)
|
||||
|
||||
# Test input as AbstractArray and cvtColor
|
||||
img_gray = OpenCV.cvtColor(img, OpenCV.COLOR_RGB2GRAY)
|
||||
|
||||
@test size(img_gray, 1) == 1 && size(img_gray, 2) == size(img, 2) && size(img_gray, 3) == size(img, 3)
|
||||
|
||||
# Exception test
|
||||
try
|
||||
# This should throw an error
|
||||
OpenCV.cvtColor(img_gray, OpenCV.COLOR_RGB2GRAY)
|
||||
exit(1)
|
||||
catch
|
||||
# Error caught so we can continue
|
||||
end
|
||||
|
||||
ve = view(img, :,200:300, 200:300)
|
||||
|
||||
# Auto-conversion from-to OpenCV types
|
||||
ve_gray = OpenCV.cvtColor(ve, OpenCV.COLOR_RGB2GRAY)
|
||||
|
||||
# Shape check
|
||||
@test size(ve_gray)[1] == 1 && size(img_gray)[1] == 1
|
||||
|
||||
|
||||
|
||||
print("imgproc test passed\n")
|
||||
@@ -0,0 +1,118 @@
|
||||
# This file is adapted from test/abstractarray.jl from Julia.
|
||||
|
||||
# This file is a part of Julia. License is MIT: https://julialang.org/license
|
||||
|
||||
A_abs = rand(5,4,3)
|
||||
A = OpenCV.Mat(A_abs)
|
||||
@testset "Bounds checking" begin
|
||||
@test checkbounds(Bool, A, 1, 1, 1) == true
|
||||
@test checkbounds(Bool, A, 5, 4, 3) == true
|
||||
@test checkbounds(Bool, A, 0, 1, 1) == false
|
||||
@test checkbounds(Bool, A, 1, 0, 1) == false
|
||||
@test checkbounds(Bool, A, 1, 1, 0) == false
|
||||
@test checkbounds(Bool, A, 6, 4, 3) == false
|
||||
@test checkbounds(Bool, A, 5, 5, 3) == false
|
||||
@test checkbounds(Bool, A, 5, 4, 4) == false
|
||||
@test checkbounds(Bool, A, 1) == true # linear indexing
|
||||
@test checkbounds(Bool, A, 60) == true
|
||||
@test checkbounds(Bool, A, 61) == false
|
||||
@test checkbounds(Bool, A, 2, 2, 2, 1) == true # extra indices
|
||||
@test checkbounds(Bool, A, 2, 2, 2, 2) == false
|
||||
@test checkbounds(Bool, A, 1, 1) == false
|
||||
@test checkbounds(Bool, A, 1, 12) == false
|
||||
@test checkbounds(Bool, A, 5, 12) == false
|
||||
@test checkbounds(Bool, A, 1, 13) == false
|
||||
@test checkbounds(Bool, A, 6, 12) == false
|
||||
end
|
||||
|
||||
@testset "single CartesianIndex" begin
|
||||
@test checkbounds(Bool, A, CartesianIndex((1, 1, 1))) == true
|
||||
@test checkbounds(Bool, A, CartesianIndex((5, 4, 3))) == true
|
||||
@test checkbounds(Bool, A, CartesianIndex((0, 1, 1))) == false
|
||||
@test checkbounds(Bool, A, CartesianIndex((1, 0, 1))) == false
|
||||
@test checkbounds(Bool, A, CartesianIndex((1, 1, 0))) == false
|
||||
@test checkbounds(Bool, A, CartesianIndex((6, 4, 3))) == false
|
||||
@test checkbounds(Bool, A, CartesianIndex((5, 5, 3))) == false
|
||||
@test checkbounds(Bool, A, CartesianIndex((5, 4, 4))) == false
|
||||
@test checkbounds(Bool, A, CartesianIndex((1,))) == false
|
||||
@test checkbounds(Bool, A, CartesianIndex((60,))) == false
|
||||
@test checkbounds(Bool, A, CartesianIndex((61,))) == false
|
||||
@test checkbounds(Bool, A, CartesianIndex((2, 2, 2, 1,))) == true
|
||||
@test checkbounds(Bool, A, CartesianIndex((2, 2, 2, 2,))) == false
|
||||
@test checkbounds(Bool, A, CartesianIndex((1, 1,))) == false
|
||||
@test checkbounds(Bool, A, CartesianIndex((1, 12,))) == false
|
||||
@test checkbounds(Bool, A, CartesianIndex((5, 12,))) == false
|
||||
@test checkbounds(Bool, A, CartesianIndex((1, 13,))) == false
|
||||
@test checkbounds(Bool, A, CartesianIndex((6, 12,))) == false
|
||||
end
|
||||
|
||||
@testset "mix of CartesianIndex and Int" begin
|
||||
@test checkbounds(Bool, A, CartesianIndex((1,)), 1, CartesianIndex((1,))) == true
|
||||
@test checkbounds(Bool, A, CartesianIndex((5, 4)), 3) == true
|
||||
@test checkbounds(Bool, A, CartesianIndex((0, 1)), 1) == false
|
||||
@test checkbounds(Bool, A, 1, CartesianIndex((0, 1))) == false
|
||||
@test checkbounds(Bool, A, 1, 1, CartesianIndex((0,))) == false
|
||||
@test checkbounds(Bool, A, 6, CartesianIndex((4, 3))) == false
|
||||
@test checkbounds(Bool, A, 5, CartesianIndex((5,)), 3) == false
|
||||
@test checkbounds(Bool, A, CartesianIndex((5,)), CartesianIndex((4,)), CartesianIndex((4,))) == false
|
||||
end
|
||||
|
||||
@testset "vector indices" begin
|
||||
@test checkbounds(Bool, A, 1:5, 1:4, 1:3) == true
|
||||
@test checkbounds(Bool, A, 0:5, 1:4, 1:3) == false
|
||||
@test checkbounds(Bool, A, 1:5, 0:4, 1:3) == false
|
||||
@test checkbounds(Bool, A, 1:5, 1:4, 0:3) == false
|
||||
@test checkbounds(Bool, A, 1:6, 1:4, 1:3) == false
|
||||
@test checkbounds(Bool, A, 1:5, 1:5, 1:3) == false
|
||||
@test checkbounds(Bool, A, 1:5, 1:4, 1:4) == false
|
||||
@test checkbounds(Bool, A, 1:60) == true
|
||||
@test checkbounds(Bool, A, 1:61) == false
|
||||
@test checkbounds(Bool, A, 2, 2, 2, 1:1) == true # extra indices
|
||||
@test checkbounds(Bool, A, 2, 2, 2, 1:2) == false
|
||||
@test checkbounds(Bool, A, 1:5, 1:4) == false
|
||||
@test checkbounds(Bool, A, 1:5, 1:12) == false
|
||||
@test checkbounds(Bool, A, 1:5, 1:13) == false
|
||||
@test checkbounds(Bool, A, 1:6, 1:12) == false
|
||||
end
|
||||
|
||||
@testset "logical" begin
|
||||
@test checkbounds(Bool, A, trues(5), trues(4), trues(3)) == true
|
||||
@test checkbounds(Bool, A, trues(6), trues(4), trues(3)) == false
|
||||
@test checkbounds(Bool, A, trues(5), trues(5), trues(3)) == false
|
||||
@test checkbounds(Bool, A, trues(5), trues(4), trues(4)) == false
|
||||
@test checkbounds(Bool, A, trues(60)) == true
|
||||
@test checkbounds(Bool, A, trues(61)) == false
|
||||
@test checkbounds(Bool, A, 2, 2, 2, trues(1)) == true # extra indices
|
||||
@test checkbounds(Bool, A, 2, 2, 2, trues(2)) == false
|
||||
@test checkbounds(Bool, A, trues(5), trues(12)) == false
|
||||
@test checkbounds(Bool, A, trues(5), trues(13)) == false
|
||||
@test checkbounds(Bool, A, trues(6), trues(12)) == false
|
||||
@test checkbounds(Bool, A, trues(5, 4, 3)) == true
|
||||
@test checkbounds(Bool, A, trues(5, 4, 2)) == false
|
||||
@test checkbounds(Bool, A, trues(5, 12)) == false
|
||||
@test checkbounds(Bool, A, trues(1, 5), trues(1, 4, 1), trues(1, 1, 3)) == false
|
||||
@test checkbounds(Bool, A, trues(1, 5), trues(1, 4, 1), trues(1, 1, 2)) == false
|
||||
@test checkbounds(Bool, A, trues(1, 5), trues(1, 5, 1), trues(1, 1, 3)) == false
|
||||
@test checkbounds(Bool, A, trues(1, 5), :, 2) == false
|
||||
end
|
||||
|
||||
@testset "array of CartesianIndex" begin
|
||||
@test checkbounds(Bool, A, [CartesianIndex((1, 1, 1))]) == true
|
||||
@test checkbounds(Bool, A, [CartesianIndex((5, 4, 3))]) == true
|
||||
@test checkbounds(Bool, A, [CartesianIndex((0, 1, 1))]) == false
|
||||
@test checkbounds(Bool, A, [CartesianIndex((1, 0, 1))]) == false
|
||||
@test checkbounds(Bool, A, [CartesianIndex((1, 1, 0))]) == false
|
||||
@test checkbounds(Bool, A, [CartesianIndex((6, 4, 3))]) == false
|
||||
@test checkbounds(Bool, A, [CartesianIndex((5, 5, 3))]) == false
|
||||
@test checkbounds(Bool, A, [CartesianIndex((5, 4, 4))]) == false
|
||||
@test checkbounds(Bool, A, [CartesianIndex((1, 1))], 1) == true
|
||||
@test checkbounds(Bool, A, [CartesianIndex((5, 4))], 3) == true
|
||||
@test checkbounds(Bool, A, [CartesianIndex((0, 1))], 1) == false
|
||||
@test checkbounds(Bool, A, [CartesianIndex((1, 0))], 1) == false
|
||||
@test checkbounds(Bool, A, [CartesianIndex((1, 1))], 0) == false
|
||||
@test checkbounds(Bool, A, [CartesianIndex((6, 4))], 3) == false
|
||||
@test checkbounds(Bool, A, [CartesianIndex((5, 5))], 3) == false
|
||||
@test checkbounds(Bool, A, [CartesianIndex((5, 4))], 4) == false
|
||||
end
|
||||
|
||||
println("OpenCV.Mat tests passed")
|
||||
@@ -0,0 +1,29 @@
|
||||
function detect(img::OpenCV.InputArray, cascade)
|
||||
rects = OpenCV.detectMultiScale(cascade, img)
|
||||
return (rects[1].x, rects[1].y, rects[1].width+rects[1].x, rects[1].height+rects[1].y)
|
||||
end
|
||||
|
||||
|
||||
function IOU(boxA, boxB)
|
||||
xA = max(boxA[1], boxB[1])
|
||||
yA = max(boxA[2], boxB[2])
|
||||
xB = min(boxA[3], boxB[3])
|
||||
yB = min(boxA[4], boxB[4])
|
||||
interArea = max(0, xB - xA + 1) * max(0, yB - yA + 1)
|
||||
boxAArea = (boxA[3] - boxA[1] + 1) * (boxA[4] - boxA[2] + 1)
|
||||
boxBArea = (boxB[3] - boxB[1] + 1) * (boxB[4] - boxB[2] + 1)
|
||||
iou = interArea / float(boxAArea + boxBArea - interArea)
|
||||
return iou
|
||||
end
|
||||
|
||||
cascade = OpenCV.CascadeClassifier(joinpath(test_dir, "cascadeandhog", "cascades", "haarcascade_frontalface_alt.xml"))
|
||||
|
||||
img = OpenCV.imread(joinpath(test_dir, "cascadeandhog", "images", "mona-lisa.png"), OpenCV.IMREAD_GRAYSCALE)
|
||||
|
||||
rect = detect(img, cascade)
|
||||
|
||||
expected_rect = (164,119,306,261)
|
||||
|
||||
@test IOU(rect, expected_rect) > 0.95
|
||||
|
||||
print("objdetect test passed\n")
|
||||
@@ -0,0 +1,15 @@
|
||||
print("Loading module\n")
|
||||
|
||||
using OpenCV
|
||||
using Test
|
||||
|
||||
|
||||
test_dir = joinpath(ENV["OPENCV_TEST_DATA_PATH"], "cv")
|
||||
|
||||
include("test_mat.jl")
|
||||
include("test_feature2d.jl")
|
||||
include("test_imgproc.jl")
|
||||
include("test_objdetect.jl")
|
||||
include("test_dnn.jl")
|
||||
|
||||
exit(0)
|
||||
Reference in New Issue
Block a user