尝试分割路径图像,但是我不能,为什么?

时间:2019-05-28 02:41:28

标签: python

我想分割路径,但对我说IndexError:列表索引超出范围

我在jupyter中运行它,我使用python 3

X = [] # Image data
y = [] # Labels

# Loops through imagepaths to load images and labels into arrays
for path in imagepaths:
  img = cv2.imread(path) # Reads image and returns np.array
  img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Converts into the corret colorspace (GRAY)
  img = cv2.resize(img, (320, 120)) # Reduce image size so training can be faster
  X.append(img)

  # Processing label in image path
  category = path.split("/")[3]
  label = int(category.split("_")[0][1]) # We need to convert 10_down to 00_down, or else it crashes
  y.append(label)

回溯错误是

> IndexError                                Traceback (most recent call
> last) <ipython-input-32-3d939c3e12f8> in <module>
>      10 
>      11   # Processing label in image path
> ---> 12   category = path.split("/")[3]
>      13   label = int(category.split("_")[0][1]) # We need to convert 10_down to 00_down, or else it crashes
>      14   y.append(label)
> 
> IndexError: list index out of range

0 个答案:

没有答案