File: test_cudaimgproc.py

package info (click to toggle)
opencv 4.5.1%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 268,248 kB
  • sloc: cpp: 969,170; xml: 682,525; python: 36,732; lisp: 30,170; java: 25,155; ansic: 7,927; javascript: 5,643; objc: 2,041; sh: 935; cs: 601; perl: 494; makefile: 145
file content (93 lines) | stat: -rw-r--r-- 3,466 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
import os
import cv2 as cv
import numpy as np

from tests_common import NewOpenCVTests, unittest

class cudaimgproc_test(NewOpenCVTests):
    def setUp(self):
        super(cudaimgproc_test, self).setUp()
        if not cv.cuda.getCudaEnabledDeviceCount():
            self.skipTest("No CUDA-capable device is detected")

    def test_cudaimgproc(self):
        npC1 = (np.random.random((128, 128)) * 255).astype(np.uint8)
        npC3 = (np.random.random((128, 128, 3)) * 255).astype(np.uint8)
        npC4 = (np.random.random((128, 128, 4)) * 255).astype(np.uint8)
        cuC1 = cv.cuda_GpuMat()
        cuC3 = cv.cuda_GpuMat()
        cuC4 = cv.cuda_GpuMat()
        cuC1.upload(npC1)
        cuC3.upload(npC3)
        cuC4.upload(npC4)

        cv.cuda.cvtColor(cuC3, cv.COLOR_RGB2HSV)
        cv.cuda.demosaicing(cuC1, cv.cuda.COLOR_BayerGR2BGR_MHT)
        cv.cuda.gammaCorrection(cuC3)
        cv.cuda.alphaComp(cuC4, cuC4, cv.cuda.ALPHA_XOR)
        cv.cuda.calcHist(cuC1)
        cv.cuda.equalizeHist(cuC1)
        cv.cuda.evenLevels(3, 0, 255)
        cv.cuda.meanShiftFiltering(cuC4, 10, 5)
        cv.cuda.meanShiftProc(cuC4, 10, 5)
        cv.cuda.bilateralFilter(cuC3, 3, 16, 3)
        cv.cuda.blendLinear

        cuRes = cv.cuda.meanShiftSegmentation(cuC4, 10, 5, 5)
        cuDst = cv.cuda_GpuMat(cuC4.size(),cuC4.type())
        cv.cuda.meanShiftSegmentation(cuC4, 10, 5, 5, cuDst)
        self.assertTrue(np.allclose(cuRes.download(),cuDst.download()))

        clahe = cv.cuda.createCLAHE()
        clahe.apply(cuC1, cv.cuda_Stream.Null())

        histLevels = cv.cuda.histEven(cuC3, 20, 0, 255)
        cv.cuda.histRange(cuC1, histLevels)

        detector = cv.cuda.createCannyEdgeDetector(0, 100)
        detector.detect(cuC1)

        detector = cv.cuda.createHoughLinesDetector(3, np.pi / 180, 20)
        detector.detect(cuC1)

        detector = cv.cuda.createHoughSegmentDetector(3, np.pi / 180, 20, 5)
        detector.detect(cuC1)

        detector = cv.cuda.createHoughCirclesDetector(3, 20, 10, 10, 20, 100)
        detector.detect(cuC1)

        detector = cv.cuda.createGeneralizedHoughBallard()
        #BUG: detect accept only Mat!
        #Even if generate_gpumat_decls is set to True, it only wraps overload CUDA functions.
        #The problem is that Mat and GpuMat are not fully compatible to enable system-wide overloading
        #detector.detect(cuC1, cuC1, cuC1)

        detector = cv.cuda.createGeneralizedHoughGuil()
        #BUG: same as above..
        #detector.detect(cuC1, cuC1, cuC1)

        detector = cv.cuda.createHarrisCorner(cv.CV_8UC1, 15, 5, 1)
        detector.compute(cuC1)

        detector = cv.cuda.createMinEigenValCorner(cv.CV_8UC1, 15, 5, 1)
        detector.compute(cuC1)

        detector = cv.cuda.createGoodFeaturesToTrackDetector(cv.CV_8UC1)
        detector.detect(cuC1)

        matcher = cv.cuda.createTemplateMatching(cv.CV_8UC1, cv.TM_CCOEFF_NORMED)
        matcher.match(cuC3, cuC3)

        self.assertTrue(True) #It is sufficient that no exceptions have been there

    def test_cvtColor(self):
        npMat = (np.random.random((128, 128, 3)) * 255).astype(np.uint8)
        cuMat = cv.cuda_GpuMat()
        cuMat.upload(npMat)

        self.assertTrue(np.allclose(cv.cuda.cvtColor(cuMat, cv.COLOR_BGR2HSV).download(),
                                         cv.cvtColor(npMat, cv.COLOR_BGR2HSV)))

if __name__ == '__main__':
    NewOpenCVTests.bootstrap()