feiyuhuahuo / create-a-hdf5-data-set-for-deep-learning

create your own data set with python library h5py and a simple example for image recognition

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

error in function resize

Matios-zenebe opened this issue · comments

hdf5_path='/Users/matioszenebegezahegn/Desktop/SynthText-master/data/image.hdf5'
image_directory='/Users/matioszenebegezahegn/Desktop/SynthText-master/data/bg_img/*.jpg'

addrs = glob.glob(image_directory)
images_shape = (len(addrs), 128, 128, 3)

open a hdf5 file and create earrays

f = h5py.File(hdf5_path, mode='w')

PIL.Image: the pixels range is 0-255,dtype is uint.

matplotlib: the pixels range is 0-1,dtype is float.

f.create_dataset("image", images_shape, np.uint8)

loop over train paths

for i in range(len(addrs)):
addr = addrs[i]
img = cv2.imread(addr)
img = cv2.resize(img, (128, 128), interpolation=cv2.INTER_CUBIC)# resize to (128,128)
#img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # cv2 load images as BGR, convert it to RGB
f["image"][i, ...] = img[None]
f.close()


error Traceback (most recent call last)
in ()
15 addr = addrs[i]
16 img = cv2.imread(addr)
---> 17 img = cv2.resize(img, (128, 128), interpolation=cv2.INTER_CUBIC)# resize to (128,128)
18 #img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # cv2 load images as BGR, convert it to RGB
19 f["image"][i, ...] = img[None]

error: /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/imgwarp.cpp:3483: error: (-215) ssize.width > 0 && ssize.height > 0 in function resize

why the error comes? any ideas pls.

It's being almost six months no one replied. Hence, I decided to answer this question as someone else might face the same issue in the future.
Most probably your bg_img directory contains two folders, i.e., folder-1 and folder-2. Hence, when you're using image_directory='/Users/matioszenebegezahegn/Desktop/SynthText-master/data/bg_img/*.jpg' getting the above error. Replace this line with below to solve this issue.

Solution:

image_directory='/Users/matioszenebegezahegn/Desktop/SynthText-master/data/bg_img/*/*.jpg'