警告不能 open/read 文件:检查文件 path/integrity
warning can't open/read file: check file path/integrity
images_per_class = 80
fixed_size = tuple((500, 500))
train_path = "dataset/train"
train_labels = os.listdir(train_path)
for training_name in train_labels:
dir = os.path.join(train_path, training_name)
current_label = training_name
for x in range(1,images_per_class+1):
# get the image file name
file = dir + "/" + str(x) + ".jpg"
# read the image and resize it to a fixed-size
image = cv2.imread(file)
image = cv2.resize(image, fixed_size)
当我 运行 这段代码出现这个错误时
error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\resize.cpp:4052: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
和这个警告[ WARN:0@19.045] global D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_('dataset/train\Apple/1.jpg'): can't open/read file: check file path/integrity
我没有安装 opencv 的问题,因为我之前使用过它,并且使用了另一个代码,请提供任何帮助
file = dir + "/" + str(x) + ".jpg"
尝试将此行替换为:
file = dir + "\" + str(x) + ".jpg"
这个/不正确
正确的是\
亲爱的,对我来说,这个问题与文件扩展名有关。我放置了扩展名 .JPEG,而实际扩展名是 .jpg。更正扩展名清除了警告。谢谢
最近我遇到了同样的问题,问题是文件不存在。我意识到文件名也可能是个问题。
images_per_class = 80
fixed_size = tuple((500, 500))
train_path = "dataset/train"
train_labels = os.listdir(train_path)
for training_name in train_labels:
dir = os.path.join(train_path, training_name)
current_label = training_name
for x in range(1,images_per_class+1):
# get the image file name
file = dir + "/" + str(x) + ".jpg"
# read the image and resize it to a fixed-size
image = cv2.imread(file)
image = cv2.resize(image, fixed_size)
当我 运行 这段代码出现这个错误时
error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\resize.cpp:4052: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
和这个警告[ WARN:0@19.045] global D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_('dataset/train\Apple/1.jpg'): can't open/read file: check file path/integrity
我没有安装 opencv 的问题,因为我之前使用过它,并且使用了另一个代码,请提供任何帮助
file = dir + "/" + str(x) + ".jpg"
尝试将此行替换为:
file = dir + "\" + str(x) + ".jpg"
这个/不正确
正确的是\
亲爱的,对我来说,这个问题与文件扩展名有关。我放置了扩展名 .JPEG,而实际扩展名是 .jpg。更正扩展名清除了警告。谢谢
最近我遇到了同样的问题,问题是文件不存在。我意识到文件名也可能是个问题。