diff --git a/modules/python/test/test.py b/modules/python/test/test.py index f9213cffbc..aa66e92344 100755 --- a/modules/python/test/test.py +++ b/modules/python/test/test.py @@ -17,19 +17,6 @@ import numpy as np import cv2 import argparse -# local test modules -from test_digits import digits_test -from test_calibration import calibration_test -from test_squares import squares_test -from test_texture_flow import texture_flow_test -from test_fitline import fitline_test -from test_houghcircles import houghcircles_test -from test_houghlines import houghlines_test -from test_gaussian_mix import gaussian_mix_test -from test_facedetect import facedetect_test -from test_kmeans import kmeans_test -from test_morphology import morphology_test - # Python 3 moved urlopen to urllib.requests try: from urllib.request import urlopen @@ -40,6 +27,12 @@ from tests_common import NewOpenCVTests # Tests to run first; check the handful of basic operations that the later tests rely on +basedir = os.path.abspath(os.path.dirname(__file__)) + +def load_tests(loader, tests, pattern): + tests.addTests(loader.discover(basedir, pattern='test_*.py')) + return tests + class Hackathon244Tests(NewOpenCVTests): def test_int_array(self): diff --git a/modules/python/test/test_calibration.py b/modules/python/test/test_calibration.py index 4c275a0d23..48b53ff9b2 100644 --- a/modules/python/test/test_calibration.py +++ b/modules/python/test/test_calibration.py @@ -11,7 +11,6 @@ from __future__ import print_function import numpy as np import cv2 - from tests_common import NewOpenCVTests class calibration_test(NewOpenCVTests): diff --git a/modules/python/test/test_dft.py b/modules/python/test/test_dft.py new file mode 100644 index 0000000000..f796939970 --- /dev/null +++ b/modules/python/test/test_dft.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python + +''' +Test for disctrete fourier transform (dft) +''' + +# Python 2/3 compatibility +from __future__ import print_function + +import cv2 +import numpy as np +import sys + +from tests_common import NewOpenCVTests + +class dft_test(NewOpenCVTests): + def test_dft(self): + + img = self.get_sample('samples/data/rubberwhale1.png', 0) + eps = 0.001 + + #test direct transform + refDft = np.fft.fft2(img) + refDftShift = np.fft.fftshift(refDft) + refMagnitide = np.log(1.0 + np.abs(refDftShift)) + + testDft = cv2.dft(np.float32(img),flags = cv2.DFT_COMPLEX_OUTPUT) + testDftShift = np.fft.fftshift(testDft) + testMagnitude = np.log(1.0 + cv2.magnitude(testDftShift[:,:,0], testDftShift[:,:,1])) + + refMagnitide = cv2.normalize(refMagnitide, 0.0, 1.0, cv2.NORM_MINMAX) + testMagnitude = cv2.normalize(testMagnitude, 0.0, 1.0, cv2.NORM_MINMAX) + + self.assertLess(cv2.norm(refMagnitide - testMagnitude), eps) + + #test inverse transform + img_back = np.fft.ifft2(refDft) + img_back = np.abs(img_back) + + img_backTest = cv2.idft(testDft) + img_backTest = cv2.magnitude(img_backTest[:,:,0], img_backTest[:,:,1]) + + img_backTest = cv2.normalize(img_backTest, 0.0, 1.0, cv2.NORM_MINMAX) + img_back = cv2.normalize(img_back, 0.0, 1.0, cv2.NORM_MINMAX) + + self.assertLess(cv2.norm(img_back - img_backTest), eps) \ No newline at end of file diff --git a/modules/python/test/test_morphology.py b/modules/python/test/test_morphology.py index d7abda4ede..309c80cfd2 100644 --- a/modules/python/test/test_morphology.py +++ b/modules/python/test/test_morphology.py @@ -18,14 +18,14 @@ class morphology_test(NewOpenCVTests): def test_morphology(self): - fn = 'samples/data/baboon.jpg' + fn = 'samples/data/rubberwhale1.png' img = self.get_sample(fn) modes = ['erode/dilate', 'open/close', 'blackhat/tophat', 'gradient'] str_modes = ['ellipse', 'rect', 'cross'] - referenceHashes = { modes[0]: '1bd14fc814e41b80ce7816bc04f60b65', modes[1] : '1bd14fc814e41b80ce7816bc04f60b65', - modes[2] : 'cb18a5d28e77522dfec6a6255bc3847e', modes[3] : '84909517e4866aa079f4b2e2906bf47b'} + referenceHashes = { modes[0]: '071a526425b79e45b4d0d71ef51b0562', modes[1] : '071a526425b79e45b4d0d71ef51b0562', + modes[2] : '427e89f581b7df1b60a831b1ed4c8618', modes[3] : '0dd8ad251088a63d0dd022bcdc57361c'} def update(cur_mode): cur_str_mode = str_modes[0]