mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-16 22:35:51 +08:00

Julia Bindings GSoC - phase1 * Julia Phase 1 first commit * a few fixes to compile julia bindings on mac * Readme changes * Allow usage before installation and update README * Add CxxWrap installation and fix Mac build bug * CMake fixes and test refactoring * add tests, fix trailing whitespace, disable array-vec conversion * Fix trailing whiteline and warning * Add module documentation and fix tests in CMake * Change copyright block, CMake variable name * copy => copy_if_different * fix status dump and return lines * Remove Julia_Found outside init.cmake * change indentation Co-authored-by: Vadim Pisarevsky <vadim.pisarevsky@gmail.com>
30 lines
953 B
Julia
30 lines
953 B
Julia
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")
|