【问题标题】:Display images where the location of the images are in a text file using python使用python显示图像位置在文本文件中的图像
【发布时间】:2021-02-16 17:49:08
【问题描述】:

我是 pyhton 学习 CNN 的新手,希望得到您的帮助来解决我的问题。

我有一个文本文件,其中包含如下详细信息,其中给出了被分类的各个图像的位置,

实际的猫图片: 输出/图像/IMG_1547.JPG 输出/图像/IMG_1548.JPG 输出/图像/IMG_1548.JPG 输出/图像/IMG_1555.JPG

实际的狗图片: 输出/图像/IMG_1557.JPG 输出/图像/IMG_1598.JPG 输出/图像/IMG_1538.JPG 输出/图像/IMG_1545.JPG

如何编写 python 脚本来在我的 jupyter 笔记本上显示属于实际猫图像和实际狗图像的列表。

【问题讨论】:

    标签: python


    【解决方案1】:
    import os
    import matplotlib.pyplot as plt
    
    
    def plot_sample_of_img(nrows, ncols, img_paths):
        fig = plt.gcf()
        fig.set_size_inches(ncols * 4, nrows * 4)
    
        for i, img_path in enumerate(img_paths):
            # Set up subplot; subplot indices start at 1
            sp = plt.subplot(nrows, ncols, i + 1)
            sp.axis('Off')  # Don't show axes (or gridlines)
            img = mpimg.imread(img_path)
            plt.imshow(img)
        plt.show()
    
    
    with open("cat.txt","r") as pf:
         height = width = int(sqrt(len(pf.readlines))
         plot_sample_of_img(nrows, ncols, pf.readlines)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多