本文介绍了错误:(-215)ssize.width> 0&& ssize.height>函数调整大小为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建图像处理分类器,除此行外,整个代码都正确-

I am building image processing classifier the whole code in right except this line -

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

此行给我一个错误

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

我的代码-

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-'+'{}\n'.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)

推荐答案

好吧,显然这行input_img=cv2.imread(data_path + '/'+ dataset + '/'+ img )返回一个空数组.

Well, obviously this lineinput_img=cv2.imread(data_path + '/'+ dataset + '/'+ img )return a empty array.

读取之前,应先检查图像是否存在.并且请停止使用字符串组合来连接文件路径,使用python os.path.join是更好的选择.

You should check whether image is exist first before reading. And please stop using string combination to join file path, use python os.path.join is better choice.

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

这篇关于错误:(-215)ssize.width> 0&& ssize.height>函数调整大小为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 21:31