Hướng dẫn read images from multiple folders python - đọc hình ảnh từ nhiều thư mục python

Tôi muốn đọc nhiều hình ảnh .jpg, có trong 3 thư mục riêng biệt. 3 thư mục trên cùng một con đường. Tôi đã cố gắng làm điều đó như thế này:

path2 = os.path.abspath['Type_1']
path2 = os.path.abspath['Type_2']
path3 = os.path.abspath['Type_3']
folder = os.path.join[path2, path2, path3]

def load_images_from_folder[folder]:
    images = []
    for filename in os.listdir[folder]:
        if filename.endswith[".jpg"]:
            img = cv2.imread[os.path.join[folder, filename]]
            if img is not None:
                images.append[img]
            return images

print[load_images_from_folder[folder]]

Nhưng nó chỉ trả lại con đường cuối cùng và không phải tất cả chúng. Tôi cũng đã cố gắng sử dụng các đường dẫn tương đối, chẳng hạn như:

path2 = os.path.relpath['Type_1']
path2 = os.path.relpath['Type_2']
path3 = os.path.relpath['Type_3']
folder = os.path.join[os.path.sep, path2, path2, path3]

Nhưng vẫn là vấn đề tương tự. Có ai có thể giúp cho việc này không?

Đã hỏi ngày 16 tháng 5 năm 2017 lúc 13:15May 16, 2017 at 13:15

0

Dòng return images của bạn nằm trong vòng lặp của bạn, vì vậy nó sẽ trở lại ngay khi tìm thấy bất kỳ kết quả phù hợp nào. Bạn chỉ muốn nó trở lại sau toàn bộ vòng lặp như đã hoàn thành.

Giảm thụt vào câu lệnh trả về để nó nằm sau vòng lặp thay vì bên trong nó.

def load_images_from_folder[folder]:
    images = []
    for filename in os.listdir[folder]:
        if filename.endswith[".jpg"]:
            img = cv2.imread[os.path.join[folder, filename]]
            if img is not None:
                images.append[img]
    return images

[Edit]

Nếu bạn muốn xem trong nhiều thư mục liền kề, bạn muốn một cái gì đó như thế này:

root_folder = '[whatever]/data/train'
folders = [os.path.join[root_folder, x] for x in ['Type_1', 'Type_2', 'Type_3']]
all_images = [img for folder in folders for img in load_images_from_folder[folder]]

Điều đó sẽ gọi load_images trên mỗi thư mục và đặt tất cả các kết quả vào một danh sách.

Đã trả lời ngày 16 tháng 5 năm 2017 lúc 13:21May 16, 2017 at 13:21

Khelwoodkhelwoodkhelwood

53.3K13 Huy hiệu vàng80 Huy hiệu bạc100 Huy hiệu đồng13 gold badges80 silver badges100 bronze badges

4

Nếu tôi hiểu chính xác sự cố, cấu trúc tệp của bạn trông như sau:

- Type1
    - Image1.jpg
    - Image2.jpg
- Type2
    - Image1.jpg
    - Image2.jpg
- Type3
    - Image1.jpg
    - Image2.jpg

Nếu điều này là đúng, thì cuộc gọi OS.Path.join là sai lầm [nó sẽ dẫn đến một chuỗi có ghi "Type1/type2/type3" không đạt được gì cho bạn].

Tôi nghĩ rằng mã bạn đang tìm kiếm như sau:

def load_images_from_folder[folder]:
    images = []
    for filename in os.listdir[folder]:
        if any[[filename.endswith[x] for x in ['.jpeg', '.jpg']]]:
            img = cv2.imread[os.path.join[folder, filename]]
            if img is not None:
                images.append[img]
    return images

folders = [
    'Type1',
    'Type2',
    'Type3',
]

for folder in folders:
    images = load_images_from_folder[folder]
    # your code that does something with the return images goes here

Đã trả lời ngày 16 tháng 5 năm 2017 lúc 13:28May 16, 2017 at 13:28

2

Tôi biết điều này thực sự cũ, nhưng điều này đã làm việc cho tôi gần đây.

 def create_dataset[img_folder]:
    img_data_array=[]
    class_name=[]

    for dirl in os.listdir[img_folder]:
        for file in os.listdir[os.path.join[img_folder,dirl]]:
        
            if any[[file.endswith[x] for x in ['.jpeg', '.jpg']]]:
            

                 image_path=os.path.join[img_folder,dirl,file]
                 image=cv2.imread[image_path,cv2.COLOR_BGR2RGB]
             
                 img_data_array.append[image]
                 class_name.append[dirl]
    return img_data_array,class_name


img_data, class_name =create_dataset[train_folder]
        

Đã trả lời ngày 9 tháng 5 năm 2021 lúc 19:53May 9, 2021 at 19:53

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc

    Bàn luậnUsing os.listdir

    Trong bài viết này, chúng ta sẽ học cách lặp lại thông qua các hình ảnh trong một thư mục trong Python. & NBSP;

    • Phương pháp 1: Sử dụng Os.ListDiros module to interact with the operating system.
    • Ví dụ 1: Chỉ lặp qua .png chỉlistdir[] function from os to get access to the folders given in quotes.
    • Lúc đầu, chúng tôi đã nhập mô -đun HĐH để tương tác với hệ điều hành.os.listdir[] function, we iterate through the images and printed the names in order.
    • Sau đó, chúng tôi nhập chức năng listDir [] từ HĐH để có quyền truy cập vào các thư mục được đưa ra trong báo giá..png files to be loaded using the endswith[] function.

    Python3

    Sau đó, với sự trợ giúp của hàm Os.ListDir [], chúng tôi lặp lại thông qua các hình ảnh và in các tên theo thứ tự.

    Ở đây chúng tôi chỉ đề cập đến & nbsp; .png sẽ được tải bằng hàm endswith [].

    import

    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    0

    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    1
    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    2import
    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    4

    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    2
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    3
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    4
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    5
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    6

    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    7
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    8
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    9

    Output::

    Làm cách nào để đọc nhiều hình ảnh từ nhiều thư mục trong Python?

    Làm cách nào để đọc nhiều hình ảnh từ nhiều thư mục trong Python ?..png, .jpg, .jpeg files to be loaded using the endswith[] function.

    Python3

    Sau đó, với sự trợ giúp của hàm Os.ListDir [], chúng tôi lặp lại thông qua các hình ảnh và in các tên theo thứ tự.

    Ở đây chúng tôi chỉ đề cập đến & nbsp; .png sẽ được tải bằng hàm endswith [].

    import

    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    0

    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    1
    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    2import
    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    4

    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    5
    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    6
    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    7

    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    8
    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    9
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    0
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    1

    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    7
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    8
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    9

    Output:

    Ví dụ 2: lặp qua tất cả các loại hình ảnhpathlib module

    • Ở đây chúng tôi đã đề cập đến .png, .jpg, .jpeg các tệp được tải bằng hàm endswith [].pathlib module from Path.
    • def load_images_from_folder[folder]:
          images = []
          for filename in os.listdir[folder]:
              if filename.endswith[".jpg"]:
                  img = cv2.imread[os.path.join[folder, filename]]
                  if img is not None:
                      images.append[img]
          return images
      
      2
      def load_images_from_folder[folder]:
          images = []
          for filename in os.listdir[folder]:
              if filename.endswith[".jpg"]:
                  img = cv2.imread[os.path.join[folder, filename]]
                  if img is not None:
                      images.append[img]
          return images
      
      3
      def load_images_from_folder[folder]:
          images = []
          for filename in os.listdir[folder]:
              if filename.endswith[".jpg"]:
                  img = cv2.imread[os.path.join[folder, filename]]
                  if img is not None:
                      images.append[img]
          return images
      
      4
      def load_images_from_folder[folder]:
          images = []
          for filename in os.listdir[folder]:
              if filename.endswith[".jpg"]:
                  img = cv2.imread[os.path.join[folder, filename]]
                  if img is not None:
                      images.append[img]
          return images
      
      5
      - Type1
          - Image1.jpg
          - Image2.jpg
      - Type2
          - Image1.jpg
          - Image2.jpg
      - Type3
          - Image1.jpg
          - Image2.jpg
      
      7
      - Type1
          - Image1.jpg
          - Image2.jpg
      - Type2
          - Image1.jpg
          - Image2.jpg
      - Type3
          - Image1.jpg
          - Image2.jpg
      
      8
      - Type1
          - Image1.jpg
          - Image2.jpg
      - Type2
          - Image1.jpg
          - Image2.jpg
      - Type3
          - Image1.jpg
          - Image2.jpg
      
      9
      def load_images_from_folder[folder]:
          images = []
          for filename in os.listdir[folder]:
              if any[[filename.endswith[x] for x in ['.jpeg', '.jpg']]]:
                  img = cv2.imread[os.path.join[folder, filename]]
                  if img is not None:
                      images.append[img]
          return images
      
      folders = [
          'Type1',
          'Type2',
          'Type3',
      ]
      
      for folder in folders:
          images = load_images_from_folder[folder]
          # your code that does something with the return images goes here
      
      0____
      def load_images_from_folder[folder]:
          images = []
          for filename in os.listdir[folder]:
              if any[[filename.endswith[x] for x in ['.jpeg', '.jpg']]]:
                  img = cv2.imread[os.path.join[folder, filename]]
                  if img is not None:
                      images.append[img]
          return images
      
      folders = [
          'Type1',
          'Type2',
          'Type3',
      ]
      
      for folder in folders:
          images = load_images_from_folder[folder]
          # your code that does something with the return images goes here
      
      1Path[] function and used it .glob[‘*.png’] function to iterate through all the images present in this folder.

    Python3

    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    7
    - Type1
        - Image1.jpg
        - Image2.jpg
    - Type2
        - Image1.jpg
        - Image2.jpg
    - Type3
        - Image1.jpg
        - Image2.jpg
    
    8
    - Type1
        - Image1.jpg
        - Image2.jpg
    - Type2
        - Image1.jpg
        - Image2.jpg
    - Type3
        - Image1.jpg
        - Image2.jpg
    
    9
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if any[[filename.endswith[x] for x in ['.jpeg', '.jpg']]]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    folders = [
        'Type1',
        'Type2',
        'Type3',
    ]
    
    for folder in folders:
        images = load_images_from_folder[folder]
        # your code that does something with the return images goes here
    
    5
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    6

    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    5
    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    6
     def create_dataset[img_folder]:
        img_data_array=[]
        class_name=[]
    
        for dirl in os.listdir[img_folder]:
            for file in os.listdir[os.path.join[img_folder,dirl]]:
            
                if any[[file.endswith[x] for x in ['.jpeg', '.jpg']]]:
                
    
                     image_path=os.path.join[img_folder,dirl,file]
                     image=cv2.imread[image_path,cv2.COLOR_BGR2RGB]
                 
                     img_data_array.append[image]
                     class_name.append[dirl]
        return img_data_array,class_name
    
    
    img_data, class_name =create_dataset[train_folder]
            
    
    6

    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    9
    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    6
     def create_dataset[img_folder]:
        img_data_array=[]
        class_name=[]
    
        for dirl in os.listdir[img_folder]:
            for file in os.listdir[os.path.join[img_folder,dirl]]:
            
                if any[[file.endswith[x] for x in ['.jpeg', '.jpg']]]:
                
    
                     image_path=os.path.join[img_folder,dirl,file]
                     image=cv2.imread[image_path,cv2.COLOR_BGR2RGB]
                 
                     img_data_array.append[image]
                     class_name.append[dirl]
        return img_data_array,class_name
    
    
    img_data, class_name =create_dataset[train_folder]
            
    
    9return images0return images1

    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    8 return images3
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    0 return images5

    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    2
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    8return images8

    Output:

    Phương pháp 3: Sử dụngglob.iglob [] glob.iglob[]

    • Lúc đầu, chúng tôi đã nhập mô -đun GLOB.glob module.
    • Sau đó, với sự trợ giúp của hàm glob.iglob [], chúng tôi lặp lại thông qua các hình ảnh và in tên theo thứ tự.glob.iglob[] function we iterate through the images and print the names in order.
    • Ở đây chúng tôi đã đề cập đến các tệp .png sẽ được tải bằng hàm endswith []..png files to be loaded using the endswith[] function.

    Python3

    import load_images0

    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    5
    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    6
     def create_dataset[img_folder]:
        img_data_array=[]
        class_name=[]
    
        for dirl in os.listdir[img_folder]:
            for file in os.listdir[os.path.join[img_folder,dirl]]:
            
                if any[[file.endswith[x] for x in ['.jpeg', '.jpg']]]:
                
    
                     image_path=os.path.join[img_folder,dirl,file]
                     image=cv2.imread[image_path,cv2.COLOR_BGR2RGB]
                 
                     img_data_array.append[image]
                     class_name.append[dirl]
        return img_data_array,class_name
    
    
    img_data, class_name =create_dataset[train_folder]
            
    
    6

    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    8
    path2 = os.path.relpath['Type_1']
    path2 = os.path.relpath['Type_2']
    path3 = os.path.relpath['Type_3']
    folder = os.path.join[os.path.sep, path2, path2, path3]
    
    9
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    0 load_images7load_images8load_images9

    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    2
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    3
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    4
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    5
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    6

    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    7
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    8
    def load_images_from_folder[folder]:
        images = []
        for filename in os.listdir[folder]:
            if filename.endswith[".jpg"]:
                img = cv2.imread[os.path.join[folder, filename]]
                if img is not None:
                    images.append[img]
        return images
    
    9

    Output::


    Làm cách nào để đọc nhiều hình ảnh từ nhiều thư mục trong Python?

    Làm cách nào để đọc nhiều hình ảnh từ nhiều thư mục trong Python ?..
    Skimage: Từ Nhập mục IOIMG = IO.Imread [.
    OpenCV: Nhập CV2# Để đọc hình ảnh là colorcv2_img = cv2.Imread [.
    Nhập khẩu Pydicom Pydicom dưới dạng DICOM ..
    Skimage từ IOIO nhập khẩu này.Imsave ["write_brain_image. PNG", IMG].

    Làm thế nào tôi có thể đọc nhiều hình ảnh trong Python được trình bày trong một thư mục?

    Lúc đầu, chúng tôi đã nhập mô -đun PATHLIB từ đường dẫn. Sau đó, chúng tôi chuyển chức năng thư mục/thư mục bên trong [] và sử dụng chức năng .glob ['*. PNG'] để lặp qua tất cả các hình ảnh có trong thư mục này.imported the pathlib module from Path. Then we pass the directory/folder inside Path[] function and used it . glob['*. png'] function to iterate through all the images present in this folder.

    Làm cách nào để xem nhiều hình ảnh trong Python?

    Approach..
    Nhập mô -đun ..
    Tải nhiều hình ảnh bằng CV2.Imread [].
    Concatenate các hình ảnh bằng cách sử dụng incatenate [], với giá trị trục được cung cấp theo yêu cầu theo hướng ..
    Hiển thị tất cả các hình ảnh bằng cv2.imshow [].
    Chờ nút bàn phím Nhấn bằng CV2.waitkey [].

    Chủ Đề