Fix loading images in python tests

This commit is contained in:
Vladislav Sovrasov
2016-01-28 17:13:58 +03:00
parent ab4d375349
commit 5625d79508
9 changed files with 28 additions and 28 deletions

View File

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