From 5625d79508c1ec7d55383ac0a1f8b13014042b37 Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Thu, 28 Jan 2016 17:13:58 +0300 Subject: [PATCH] Fix loading images in python tests --- modules/python/test/test.py | 2 -- modules/python/test/test_calibration.py | 11 +++++++---- modules/python/test/test_digits.py | 16 ++++++++-------- modules/python/test/test_facedetect.py | 8 ++++---- modules/python/test/test_gaussian_mix.py | 4 ++-- modules/python/test/test_houghcircles.py | 4 ++-- modules/python/test/test_houghlines.py | 4 ++-- modules/python/test/test_squares.py | 2 +- modules/python/test/test_texture_flow.py | 5 ++--- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/modules/python/test/test.py b/modules/python/test/test.py index 074b6ed..e0b6741 100755 --- a/modules/python/test/test.py +++ b/modules/python/test/test.py @@ -1,8 +1,6 @@ #!/usr/bin/env python - from __future__ import print_function - import unittest import random import time diff --git a/modules/python/test/test_calibration.py b/modules/python/test/test_calibration.py index af8d0fc..6a1240c 100644 --- a/modules/python/test/test_calibration.py +++ b/modules/python/test/test_calibration.py @@ -19,9 +19,12 @@ class calibration_test(NewOpenCVTests): def test_calibration(self): from glob import glob - - img_mask = '../../../samples/data/left*.jpg' # default - img_names = glob(img_mask) + img_names = [] + for i in range(1, 15): + if i < 10: + img_names.append('samples/data/left0{}.jpg'.format(str(i))) + else: + img_names.append('samples/data/left{}.jpg'.format(str(i))) square_size = 1.0 pattern_size = (9, 6) @@ -34,7 +37,7 @@ class calibration_test(NewOpenCVTests): h, w = 0, 0 img_names_undistort = [] for fn in img_names: - img = cv2.imread(fn, 0) + img = self.get_sample(fn, 0) if img is None: continue diff --git a/modules/python/test/test_digits.py b/modules/python/test/test_digits.py index 9d1d255..2aa32df 100644 --- a/modules/python/test/test_digits.py +++ b/modules/python/test/test_digits.py @@ -36,7 +36,7 @@ from numpy.linalg import norm SZ = 20 # size of each digit is SZ x SZ CLASS_N = 10 -DIGITS_FN = '../../../samples/data/digits.png' +DIGITS_FN = 'samples/data/digits.png' def split2d(img, cell_size, flatten=True): h, w = img.shape[:2] @@ -47,12 +47,6 @@ def split2d(img, cell_size, flatten=True): cells = cells.reshape(-1, sy, sx) return cells -def load_digits(fn): - digits_img = cv2.imread(fn, 0) - digits = split2d(digits_img, (SZ, SZ)) - labels = np.repeat(np.arange(CLASS_N), len(digits)/CLASS_N) - return digits, labels - def deskew(img): m = cv2.moments(img) if abs(m['mu02']) < 1e-2: @@ -134,9 +128,15 @@ from tests_common import NewOpenCVTests class digits_test(NewOpenCVTests): + def load_digits(self, fn): + digits_img = self.get_sample(fn, 0) + digits = split2d(digits_img, (SZ, SZ)) + labels = np.repeat(np.arange(CLASS_N), len(digits)/CLASS_N) + return digits, labels + def test_digits(self): - digits, labels = load_digits(DIGITS_FN) + digits, labels = self.load_digits(DIGITS_FN) # shuffle digits rand = np.random.RandomState(321) diff --git a/modules/python/test/test_facedetect.py b/modules/python/test/test_facedetect.py index 7fe64e2..e5c2f59 100644 --- a/modules/python/test/test_facedetect.py +++ b/modules/python/test/test_facedetect.py @@ -36,13 +36,13 @@ class facedetect_test(NewOpenCVTests): def test_facedetect(self): import sys, getopt - cascade_fn = "../../../data/haarcascades/haarcascade_frontalface_alt.xml" - nested_fn = "../../../data/haarcascades/haarcascade_eye.xml" + cascade_fn = self.repoPath + '/data/haarcascades/haarcascade_frontalface_alt.xml' + nested_fn = self.repoPath + '/data/haarcascades/haarcascade_eye.xml' cascade = cv2.CascadeClassifier(cascade_fn) nested = cv2.CascadeClassifier(nested_fn) - dirPath = '../../../samples/data/' + dirPath = 'samples/data/' samples = ['lena.jpg', 'kate.jpg'] faces = [] @@ -62,7 +62,7 @@ class facedetect_test(NewOpenCVTests): for sample in samples: - img = cv2.imread(dirPath + sample) + img = self.get_sample(dirPath + sample) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) gray = cv2.GaussianBlur(gray, (3, 3), 1.1) diff --git a/modules/python/test/test_gaussian_mix.py b/modules/python/test/test_gaussian_mix.py index 58802d4..cfd33ec 100644 --- a/modules/python/test/test_gaussian_mix.py +++ b/modules/python/test/test_gaussian_mix.py @@ -31,7 +31,7 @@ from tests_common import NewOpenCVTests class gaussian_mix_test(NewOpenCVTests): def test_gaussian_mix(self): - + np.random.seed(10) cluster_n = 5 img_size = 512 @@ -53,7 +53,7 @@ class gaussian_mix_test(NewOpenCVTests): for i in range(cluster_n): for j in range(cluster_n): - if (cv2.norm(means[i] - ref_distrs[j][0], cv2.NORM_L2) / cv2.norm(ref_distrs[j][0], cv2.NORM_L2) < meanEps and + if (cv2.norm(means[i] - ref_distrs[j][0], cv2.NORM_L2) / cv2.norm(ref_distrs[j][0], cv2.NORM_L2) < meanEps and cv2.norm(covs[i] - ref_distrs[j][1], cv2.NORM_L2) / cv2.norm(ref_distrs[j][1], cv2.NORM_L2) < covEps): matches_count += 1 diff --git a/modules/python/test/test_houghcircles.py b/modules/python/test/test_houghcircles.py index dc4284a..c012d30 100644 --- a/modules/python/test/test_houghcircles.py +++ b/modules/python/test/test_houghcircles.py @@ -17,9 +17,9 @@ class houghcircles_test(NewOpenCVTests): def test_houghcircles(self): - fn = "../../../samples/data/board.jpg" + fn = "samples/data/board.jpg" - src = cv2.imread(fn, 1) + src = self.get_sample(fn, 1) img = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY) img = cv2.medianBlur(img, 5) diff --git a/modules/python/test/test_houghlines.py b/modules/python/test/test_houghlines.py index b779129..9f056ce 100644 --- a/modules/python/test/test_houghlines.py +++ b/modules/python/test/test_houghlines.py @@ -26,9 +26,9 @@ class houghlines_test(NewOpenCVTests): def test_houghlines(self): - fn = "../../../samples/data/pic1.png" + fn = "/samples/data/pic1.png" - src = cv2.imread(fn) + src = self.get_sample(fn) dst = cv2.Canny(src, 50, 200) lines = cv2.HoughLinesP(dst, 1, math.pi/180.0, 40, np.array([]), 50, 10)[:,0,:] diff --git a/modules/python/test/test_squares.py b/modules/python/test/test_squares.py index 937b526..214c64b 100644 --- a/modules/python/test/test_squares.py +++ b/modules/python/test/test_squares.py @@ -61,7 +61,7 @@ class squares_test(NewOpenCVTests): def test_squares(self): - img = cv2.imread('../../../samples/data/pic1.png') + img = self.get_sample('samples/data/pic1.png') squares = find_squares(img) testSquares = [ diff --git a/modules/python/test/test_texture_flow.py b/modules/python/test/test_texture_flow.py index 46d680a..50d1e69 100644 --- a/modules/python/test/test_texture_flow.py +++ b/modules/python/test/test_texture_flow.py @@ -21,8 +21,7 @@ class texture_flow_test(NewOpenCVTests): def test_texture_flow(self): - fn = '../../../samples/data/pic6.png' - img = cv2.imread(fn) + img = self.get_sample('samples/data/pic6.png') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) h, w = img.shape[:2] @@ -43,7 +42,7 @@ class texture_flow_test(NewOpenCVTests): eps = 0.05 - testTextureVectors = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], + testTextureVectors = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [-38, 70], [-79, 3], [0, 0], [0, 0], [-39, 69], [-79, -1], [0, 0], [0, 0], [0, -79], [17, -78], [-48, -63], [65, -46], [-69, -39], [-48, -63], [-45, 66]] -- 2.7.4