I am trying to create a dataset for training a neural network to authenticate signatures. I encountered an error whlie resizing the images in my dataset.
This is my code so far
import cv2
import numpy as np
import os
from random import shuffle
from tqdm import tqdm
from PIL import Image
TRAIN_DIR = '../DATASET/TRAIN/'
TEST_DIR = '../DATASET/TEST/'
IMG_BREDTH = 250
IMG_HEIGHT = 100
LR = 1e-3
MODEL_NAME = 'signature-{}-{}.model'.format(LR, '2conv-basic')
def label_img(img):
word_label = img.split('.')[-2]
if (word_label == '1') or (word_label == '2'): return [1,0]
elif word_label == 'F': return [0,1]
def create_training_set():
training_data = []
for img in tqdm(os.listdir(TRAIN_DIR)):
label = label_img(img)
path = os.path.join(TRAIN_DIR, img)
img = cv2.resize(cv2.imread(path, cv2.IMREAD_GRAYSCALE), (IMG_BREDTH, IMG_HEIGHT))
training_data.append([np.array(img), np.array(label)])
shuffle(training_data)
np.save('training_data.npy', training_data)
return training_data
I am getting this error
14%|█▍ | 105/730 [00:00<00:00, 1040.64it/s]
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-87-57e881a5e615> in <module>()
----> 1 create_training_set()
<ipython-input-86-ed607a429014> in create_training_set()
20 path = os.path.join(TRAIN_DIR, img)
21 # img = rotateImage(img, 90)
---> 22 img = cv2.resize(cv2.imread(path, cv2.IMREAD_GRAYSCALE), (IMG_BREDTH, IMG_HEIGHT))
23 training_data.append([unq_num, np.array(img), np.array(label)])
24 unq_num += 3
error: /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/resize.cpp:4044: error: (-215) ssize.width > 0 && ssize.height > 0 in function resize
What am I doing wrong? Can someone explain the error?
Thanks in advance.