test_cudaimgproc.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 cudaimgproc_test(NewOpenCVTests):
  7. def setUp(self):
  8. super(cudaimgproc_test, self).setUp()
  9. if not cv.cuda.getCudaEnabledDeviceCount():
  10. self.skipTest("No CUDA-capable device is detected")
  11. def test_cudaimgproc(self):
  12. npC1 = (np.random.random((128, 128)) * 255).astype(np.uint8)
  13. npC3 = (np.random.random((128, 128, 3)) * 255).astype(np.uint8)
  14. npC4 = (np.random.random((128, 128, 4)) * 255).astype(np.uint8)
  15. cuC1 = cv.cuda_GpuMat()
  16. cuC3 = cv.cuda_GpuMat()
  17. cuC4 = cv.cuda_GpuMat()
  18. cuC1.upload(npC1)
  19. cuC3.upload(npC3)
  20. cuC4.upload(npC4)
  21. cv.cuda.cvtColor(cuC3, cv.COLOR_RGB2HSV)
  22. cv.cuda.demosaicing(cuC1, cv.cuda.COLOR_BayerGR2BGR_MHT)
  23. cv.cuda.gammaCorrection(cuC3)
  24. cv.cuda.alphaComp(cuC4, cuC4, cv.cuda.ALPHA_XOR)
  25. cv.cuda.calcHist(cuC1)
  26. cv.cuda.equalizeHist(cuC1)
  27. cv.cuda.evenLevels(3, 0, 255)
  28. cv.cuda.meanShiftFiltering(cuC4, 10, 5)
  29. cv.cuda.meanShiftProc(cuC4, 10, 5)
  30. cv.cuda.bilateralFilter(cuC3, 3, 16, 3)
  31. cv.cuda.blendLinear
  32. cuRes = cv.cuda.meanShiftSegmentation(cuC4, 10, 5, 5)
  33. cuDst = cv.cuda_GpuMat(cuC4.size(),cuC4.type())
  34. cv.cuda.meanShiftSegmentation(cuC4, 10, 5, 5, cuDst)
  35. self.assertTrue(np.allclose(cuRes.download(),cuDst.download()))
  36. clahe = cv.cuda.createCLAHE()
  37. clahe.apply(cuC1, cv.cuda_Stream.Null())
  38. histLevels = cv.cuda.histEven(cuC3, 20, 0, 255)
  39. cv.cuda.histRange(cuC1, histLevels)
  40. detector = cv.cuda.createCannyEdgeDetector(0, 100)
  41. detector.detect(cuC1)
  42. detector = cv.cuda.createHoughLinesDetector(3, np.pi / 180, 20)
  43. detector.detect(cuC1)
  44. detector = cv.cuda.createHoughSegmentDetector(3, np.pi / 180, 20, 5)
  45. detector.detect(cuC1)
  46. detector = cv.cuda.createHoughCirclesDetector(3, 20, 10, 10, 20, 100)
  47. detector.detect(cuC1)
  48. detector = cv.cuda.createGeneralizedHoughBallard()
  49. #BUG: detect accept only Mat!
  50. #Even if generate_gpumat_decls is set to True, it only wraps overload CUDA functions.
  51. #The problem is that Mat and GpuMat are not fully compatible to enable system-wide overloading
  52. #detector.detect(cuC1, cuC1, cuC1)
  53. detector = cv.cuda.createGeneralizedHoughGuil()
  54. #BUG: same as above..
  55. #detector.detect(cuC1, cuC1, cuC1)
  56. detector = cv.cuda.createHarrisCorner(cv.CV_8UC1, 15, 5, 1)
  57. detector.compute(cuC1)
  58. detector = cv.cuda.createMinEigenValCorner(cv.CV_8UC1, 15, 5, 1)
  59. detector.compute(cuC1)
  60. detector = cv.cuda.createGoodFeaturesToTrackDetector(cv.CV_8UC1)
  61. detector.detect(cuC1)
  62. matcher = cv.cuda.createTemplateMatching(cv.CV_8UC1, cv.TM_CCOEFF_NORMED)
  63. matcher.match(cuC3, cuC3)
  64. self.assertTrue(True) #It is sufficient that no exceptions have been there
  65. def test_cvtColor(self):
  66. npMat = (np.random.random((128, 128, 3)) * 255).astype(np.uint8)
  67. cuMat = cv.cuda_GpuMat()
  68. cuMat.upload(npMat)
  69. self.assertTrue(np.allclose(cv.cuda.cvtColor(cuMat, cv.COLOR_BGR2HSV).download(),
  70. cv.cvtColor(npMat, cv.COLOR_BGR2HSV)))
  71. if __name__ == '__main__':
  72. NewOpenCVTests.bootstrap()