Fix loading images in python tests

pull/6025/head
Vladislav Sovrasov 9 years ago
parent ab4d375349
commit 5625d79508
  1. 2
      modules/python/test/test.py
  2. 11
      modules/python/test/test_calibration.py
  3. 16
      modules/python/test/test_digits.py
  4. 8
      modules/python/test/test_facedetect.py
  5. 4
      modules/python/test/test_gaussian_mix.py
  6. 4
      modules/python/test/test_houghcircles.py
  7. 4
      modules/python/test/test_houghlines.py
  8. 2
      modules/python/test/test_squares.py
  9. 5
      modules/python/test/test_texture_flow.py

@ -1,8 +1,6 @@
#!/usr/bin/env python
from __future__ import print_function
import unittest
import random
import time

@ -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

@ -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)

@ -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)

@ -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

@ -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)

@ -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,:]

@ -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 = [

@ -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]]

Loading…
Cancel
Save