繁体   English   中英

我不能使用 python 图像路径

[英]I can't use python image paths

我有这个代码。 这是为了获取我在一组文件夹中的一组图像,并尝试将它们取出,并将 append 放入一个列表中,稍后将它们连接起来。 但是,每次我尝试使用paths.image_list时,我都没有收到任何反馈(空的 null 列表。)我不知道为什么会这样。

phases = ['Phase A', 'Phase B', 'Phase C']
sides = ['Primary', 'Secondary']
percentShorts = [round(f, 2) for f in list(np.arange(0.01, 1.0, 0.01))]
sections = ['sec_1/', 'sec_2/', 'sec_3/']
triggerTimes = [round(f, 2) for f in list(np.arange(0.06, 0.4, 0.06))]
powers= np.arange(10000, 210000,10000)
##triggerTimes = [0.3]
folders = ['input_current\\', 'output_current\\', 'output_voltage\\']
imager = ['a','b','c']

PREFIX = "C:\\Users\\Edwin\\Desktop\\PROJECT\\AI\\Data\\"
H_PREFIX = PREFIX + 'Healthy\\Scalogram\\'
F_PREFIX = PREFIX + 'Faulty\\Scalogram\\'
print("Healthy Prefix = ",H_PREFIX, "and Faulty Prefix= ", F_PREFIX)

START = 0.01
STEP = 0.01
BATCH = 99
BN = 1

percentShorts = [round(f, 2) for f in list(np.arange(START, START + STEP*BATCH, STEP))]
percentShorts = percentShorts[:BATCH]

##HEALTHY_COUNT = 718
HEALTHY_COUNT = 3
FAULTY_COUNT = len(phases)*len(sides)*BATCH*len(sections)*len(triggerTimes)

print("Healthy Count: {}".format(HEALTHY_COUNT))
print("Faulty Count: {}".format(FAULTY_COUNT))
print("Combined Count: {}".format(FAULTY_COUNT + HEALTHY_COUNT))

data = [] # Store images concatenated along the channel axis
healthLabels = [] # Indicate presence of fault or otherwise: ['Healthy', 'Faulty']
phaseLabels = [] # Store phase labels for faults: ['Phase A', 'Phase B', 'Phase C', 'None']
sideLabels = [] # Store side labels for faults: ['Primary', 'Secondary', 'None']
percentLabels = [] # Store percentage short labels for faults: [percentShort, 0]


print("[START]: Started processing Healthy Images at {}".format(datetime.now()))
print('[INFO]: Started processing Healthy Images')

# Healthy Images
for i in range(HEALTHY_COUNT):
    # List to hold horizontally-concatenated images for v-concat
    images = []

    for folder in folders:
      for power in powers:
        for ima in imager:
          newpath = H_PREFIX + '\\' +str(power)+ '\\' + folder
          imagePaths = sorted(list(paths.list_images(newpath)))
          print(imagePaths)
        # Loop over the image, read and append them to the list of images
          for imagePath in imagePaths:
            images.append(cv.cvtColor(cv.imread(imagePath), cv.COLOR_BGR2RGB))

但是每次,图像路径都返回空。 我不知道为什么,有人可以帮助我吗?

当您运行代码时,您会得到如下路径:

C:\Users\Edwin\Desktop\PROJECT\AI\Data\Healthy\Scalogram\\10000\input_current\

注意 Scalogram 和 10000 之间的双斜线。该路径不存在,因此在该路径中找不到任何图像。

在我看来,使用路径 package 来处理连接路径更容易。 这样可以避免双斜杠等错误。 除此之外,它使您的代码独立于操作系统(现在这在 linux 上不起作用,因为斜杠在 windows 和 linux 中是相反的方向)。

这是一个例子:

import os
...
folders = ['input_current', 'output_current', 'output_voltage']
...
PREFIX = os.path.join("C:", "Users", "Edwin", "Desktop", "PROJECT", "AI", "Data")
H_PREFIX = os.path.join(PREFIX, "Healthy", "Scalogram")
...
newpath = os.path.join(H_PREFIX, str(power), folder)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM