开放的简历可以不读的所有文件形式的路径

0

的问题

我的工作与数据集的72图像和72口罩。 我所附的图像进入 numpy ndarray我想cv2读取文件的路径相对应的文件 numpy ndarray.

这是路径图像和面具:

images_dir = '/content/drive/MyDrive/dataset/images'
masks_dir = '/content/drive/MyDrive/dataset/masks'

#增加的图像 numpy ndarray

file_names = np.sort(os.listdir(images_dir)) 
file_names = np.char.split(file_names, '.')
filenames = np.array([])
for i in range(len(file_names)):
    filenames = np.append(filenames, file_names[i][0])

这是我想打开的简历阅读的每一个图像,然后掩从相应的路径:

def augment_dataset(count):
    '''Function for data augmentation
        Input:
            count - total no. of images after augmentation = initial no. of images * count
        Output:
            writes augmented images (input images & segmentation masks) to the working directory
    '''
    transform_1 = augment(512, 512)
    transform_2 = augment(480, 480)
    transform_3 = augment(512, 512)
    transform_4 = augment(800, 800)
    transform_5 = augment(1024, 1024)
    transform_6 = augment(800, 800)
    transform_7 = augment(1600, 1600)
    transform_8 = augment(1920, 1280)
    
    i = 0
    for i in range(count):
        for file in filenames:
            tile = file.split('_')[1]
            img = cv2.imread(images_dir+file+'.jpg')
            img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
            mask = cv2.imread(masks_dir+file+'.png')
            mask = cv2.cvtColor(mask, cv2.COLOR_BGR2RGB)

当我运行的代码:

augment_dataset(8)

有这种错误表示:

---------------------------------------------------------------------------

error                                     Traceback (most recent call last)

<ipython-input-112-fae4beb79e15> in <module>()
----> 1 augment_dataset(8)

<ipython-input-111-121d55acd3fc> in augment_dataset(count)
     20             tile = file.split('_')[1]
     21             img = cv2.imread(images_dir+file+'.jpg')
---> 22             img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
     23             mask = cv2.imread(masks_dir+file+'.png')
     24             mask = cv2.cvtColor(mask, cv2.COLOR_BGR2RGB)

error: OpenCV(4.1.2) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

我知道,这是因为该版本没有读该文件。 所以我怎样才能使该版本的阅读该文件?

computer-vision imread opencv path
2021-11-20 09:26:23
1

最好的答案

0

在这些情况下,这是更好的 print(path/to/directory) 来看看目录是否正确。 在这种情况下,我们可以看到,我错过了 / 在路径向目录。 所以,蟒蛇不能够分析数据。 此外,您可以使用 ose.path.exists(path/to/directory) 看如果该路径存在或没有。 如果返回值 False你必须检查所指定的路径的错误

2021-11-23 19:47:17

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................