test_objdetect.jl 953 B

1234567891011121314151617181920212223242526272829
  1. function detect(img::OpenCV.InputArray, cascade)
  2. rects = OpenCV.detectMultiScale(cascade, img)
  3. return (rects[1].x, rects[1].y, rects[1].width+rects[1].x, rects[1].height+rects[1].y)
  4. end
  5. function IOU(boxA, boxB)
  6. xA = max(boxA[1], boxB[1])
  7. yA = max(boxA[2], boxB[2])
  8. xB = min(boxA[3], boxB[3])
  9. yB = min(boxA[4], boxB[4])
  10. interArea = max(0, xB - xA + 1) * max(0, yB - yA + 1)
  11. boxAArea = (boxA[3] - boxA[1] + 1) * (boxA[4] - boxA[2] + 1)
  12. boxBArea = (boxB[3] - boxB[1] + 1) * (boxB[4] - boxB[2] + 1)
  13. iou = interArea / float(boxAArea + boxBArea - interArea)
  14. return iou
  15. end
  16. cascade = OpenCV.CascadeClassifier(joinpath(test_dir, "cascadeandhog", "cascades", "haarcascade_frontalface_alt.xml"))
  17. img = OpenCV.imread(joinpath(test_dir, "cascadeandhog", "images", "mona-lisa.png"), OpenCV.IMREAD_GRAYSCALE)
  18. rect = detect(img, cascade)
  19. expected_rect = (164,119,306,261)
  20. @test IOU(rect, expected_rect) > 0.95
  21. print("objdetect test passed\n")