[英]OpenCV2 error: (-215:Assertion failed) 'cv::resize' while training the model
I am trying to train my model but I am getting below error.我正在尝试训练我的 model 但我遇到了错误。 PFB code and error: Code: datasets.py
PFB 代码和错误:代码: datasets.py
from numpy import * import csv import cv2 #import util从 numpy 导入 * 导入 csv 导入 cv2 #import util
class C100Dataset: """ X is a feature vector Y is the predictor variable """ tr_x = [] # X (data) of training set. class C100Dataset: """ X 是特征向量 Y 是预测变量 """ tr_x = [] # X(数据)训练集。 tr_y = [] # Y (label) of training set.
tr_y = [] # 训练集的 Y(标签)。 ts_x = [] # X (data) of test set.
ts_x = [] # 测试集的 X(数据)。 ts_y = [] # Y (label) of test set.
ts_y = [] # 测试集的 Y(标签)。 #filename='cifar100.csv' def init (self, filename): ## read the csv for dataset (cifar100.csv, cifar100_lt.csv or cifar100_nl.csv), # # Format: # image file path,classname
#filename='cifar100.csv' def init (self, filename): ## read the csv for dataset (cifar100.csv, cifar100_lt.csv or cifar100_nl.csv), # # Format: # image file path,classname
### TODO: Read the csv file and make the training and testing set
## YOUR CODE HERE
with open(filename) as csvfile:
reader = csv.reader(csvfile,delimiter=' ', quotechar='|')
for row in reader:
row[0] = row[0].replace('cifar100','./Downloads/dataset/')
#try
x = cv2.resize(cv2.imread(row[0]), dsize=(640, 480))
x = transpose(x, (2, 0, 1))
if 'train' in row[0].split('/'):
self.tr_x.append(x)
self.tr_y.append(row[1])
else:
self.ts_x.append(x)
self.ts_y.append(row[1])
def getDataset(self):
return [self.tr_x, self.tr_y, self.ts_x, self.ts_y]
Error:错误:
OpenCV(4.5.2) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-4g0fenxj\opencv\modules\imgproc\src\resize.cpp:4051: error: (-215:Assertion failed).ssize:empty() in function 'cv::resize OpenCV(4.5.2) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-4g0fenxj\opencv\modules\imgproc\src\resize.cpp:4051:错误:(-215:断言失败) .ssize:empty() 在 function 'cv::resize
Check that you are reading an image with cv2.imread(row[0])
.检查您是否正在使用
cv2.imread(row[0])
读取图像。 The .ssize.empty()
indicates the src
for cv2.resize
is "empty." .ssize.empty()
表示cv2.resize
的src
是“空的”。 I can recreate this same error message with a simple test case我可以用一个简单的测试用例重新创建同样的错误消息
import cv2
cv2.resize(cv2.imread('foobar'), dsize=(640, 480))
cv2.error: OpenCV(4.5.2) C:\Users\...\opencv\modules\imgproc\src\resize.cpp:4051: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.