test_cudaobjdetect.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python
  2. import os
  3. import cv2 as cv
  4. import numpy as np
  5. from tests_common import NewOpenCVTests, unittest
  6. class cudaobjdetect_test(NewOpenCVTests):
  7. def setUp(self):
  8. super(cudaobjdetect_test, self).setUp()
  9. if not cv.cuda.getCudaEnabledDeviceCount():
  10. self.skipTest("No CUDA-capable device is detected")
  11. @unittest.skipIf('OPENCV_TEST_DATA_PATH' not in os.environ,
  12. "OPENCV_TEST_DATA_PATH is not defined")
  13. def test_hog(self):
  14. img_path = os.environ['OPENCV_TEST_DATA_PATH'] + '/gpu/caltech/image_00000009_0.png'
  15. npMat = cv.cvtColor(cv.imread(img_path),cv.COLOR_BGR2BGRA)
  16. cuMat = cv.cuda_GpuMat(npMat)
  17. cuHog = cv.cuda.HOG_create()
  18. cuHog.setSVMDetector(cuHog.getDefaultPeopleDetector())
  19. loc, conf = cuHog.detect(cuMat)
  20. self.assertTrue(len(loc) == len(conf) and len(loc) > 0 and len(loc[0]) == 2)
  21. loc = cuHog.detectWithoutConf(cuMat)
  22. self.assertTrue(len(loc) > 0 and len(loc[0]) == 2)
  23. loc = cuHog.detectMultiScaleWithoutConf(cuMat)
  24. self.assertTrue(len(loc) > 0 and len(loc[0]) == 4)
  25. cuHog.setGroupThreshold(0)
  26. loc, conf = cuHog.detectMultiScale(cuMat)
  27. self.assertTrue(len(loc) == len(conf) and len(loc) > 0 and len(loc[0]) == 4)
  28. if __name__ == '__main__':
  29. NewOpenCVTests.bootstrap()