1
0
mirror of https://github.com/opencv/opencv_contrib.git synced 2025-10-19 11:21:39 +08:00
Files
opencv_contrib/modules/cudafeatures2d/misc/python/test/test_cudafeatures2d.py
cudawarped d7d6360fce Merge pull request #2396 from cudawarped:fix_python_cudawarping_cudaarithm
Add python bindings to cudaobjdetect, cudawarping and cudaarithm

* Overload cudawarping functions to generate correct python bindings.
Add python wrapper to convolution funciton.

* Added shift and hog.

* Moved cuda python tests to this repo and added python bindings to SURF.

* Fix SURF documentation and allow meanshiftsegmention to create GpuMat internaly if not passed for python bindings consistency.

* Add correct cuda SURF test case.

* Fix python mog and mog2 python bindings, add tests and  correct cudawarping documentation.

* Updated KeyPoints in cuda::ORB::Convert python wrapper to be an output argument.

* Add changes suggested by alalek

* Added changes suggested by asmorkalov
2020-01-29 12:54:42 +03:00

47 lines
1.6 KiB
Python

#!/usr/bin/env python
import os
import cv2 as cv
import numpy as np
from tests_common import NewOpenCVTests, unittest
class cudafeatures2d_test(NewOpenCVTests):
def setUp(self):
super(cudafeatures2d_test, self).setUp()
if not cv.cuda.getCudaEnabledDeviceCount():
self.skipTest("No CUDA-capable device is detected")
def test_cudafeatures2d(self):
npMat1 = self.get_sample("samples/data/right01.jpg")
npMat2 = self.get_sample("samples/data/right02.jpg")
cuMat1 = cv.cuda_GpuMat()
cuMat2 = cv.cuda_GpuMat()
cuMat1.upload(npMat1)
cuMat2.upload(npMat2)
cuMat1 = cv.cuda.cvtColor(cuMat1, cv.COLOR_RGB2GRAY)
cuMat2 = cv.cuda.cvtColor(cuMat2, cv.COLOR_RGB2GRAY)
fast = cv.cuda_FastFeatureDetector.create()
_kps = fast.detectAsync(cuMat1)
orb = cv.cuda_ORB.create()
_kps1, descs1 = orb.detectAndComputeAsync(cuMat1, None)
_kps2, descs2 = orb.detectAndComputeAsync(cuMat2, None)
self.assertTrue(len(orb.convert(_kps1)) == _kps1.size()[0])
self.assertTrue(len(orb.convert(_kps2)) == _kps2.size()[0])
bf = cv.cuda_DescriptorMatcher.createBFMatcher(cv.NORM_HAMMING)
matches = bf.match(descs1, descs2)
self.assertGreater(len(matches), 0)
matches = bf.knnMatch(descs1, descs2, 2)
self.assertGreater(len(matches), 0)
matches = bf.radiusMatch(descs1, descs2, 0.1)
self.assertGreater(len(matches), 0)
self.assertTrue(True) #It is sufficient that no exceptions have been there
if __name__ == '__main__':
NewOpenCVTests.bootstrap()