열어 이력서 읽을 수 없습니다 모든 파일 형태로 경로

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'

나는 알기 때문입 OpenCV 읽지 않았습니다. 그래서 어떻게 만들 수 있습니 openCV 하는 파일을 읽?

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

최고의 응답

0

이러한 경우에는,그것의 더 나은 print(path/to/directory) 하십시오 디렉토리가 올바른지 않습니다. 이 경우에,우리는 것을 볼 수 있을 놓쳤 / 에서의 경로를 디렉토리에 있습니다. 그래서 Python 하지 못한 분석 데이터입니다. 또한 사용할 수 있습니다 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ý
..................................................................................................................