Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

python - error: (-215) ssize.width > 0 && ssize.height > 0 in function resize

I am building an image processing classifier. This line is giving me an error:

input_img_resize=cv2.resize(input_img,(128,128))

The error:

('error: /io/opencv/modules/imgproc/src/imgwarp.cpp:3483: error: (-215) ssize.width > 0 && ssize.height > 0 in function resize')

My code:

PATH = os.getcwd()
# Define data path
data_path = PATH + '/data'
data_dir_list = os.listdir(data_path)

img_rows=128
img_cols=128
num_channel=3
num_epoch=30

num_classes = 67

img_data_list=[]

for dataset in data_dir_list:
    img_list=os.listdir(data_path+'/'+ dataset)
    print ('Loaded the images of dataset-'+'{}
'.format(dataset))
    for img in img_list:
        input_img=cv2.imread(data_path + '/'+ dataset + '/'+ img )
    
        input_img_resize=cv2.resize(input_img,(128,128))
        img_data_list.append(input_img_resize)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Well, obviously this line input_img=cv2.imread(data_path + '/'+ dataset + '/'+ img ) returns an empty array.

You should check whether the image exists first before reading. And it is better not to use string combination to join file paths, use python os.path.join instead.

image_path = os.path.join(data_path, dataset, img)
if os.path.exist():
    # Do stuff

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...