【问题标题】:Comparison of image with csv column in loop python循环python中图像与csv列的比较
【发布时间】:2020-10-29 16:07:00
【问题描述】:

问候,

问题: 我陷入了一个循环。我希望循环选择图像并将其与 csv 列(名称)进行比较(如果存在),然后进一步调整大小。图片是拉链的,我先把它们从拉链里拿出来;

from zipfile import ZipFile
file_name = "human_detection_images.zip"
with ZipFile(file_name, 'r') as zip:
   zip.extractall()
print('Done')

PATH_TO_TEST_IMAGES_DIR = pathlib.Path('/content/human_detection_images')
TEST_IMAGE_PATHS = sorted(list(PATH_TO_TEST_IMAGES_DIR.glob("*.jpg")))
TEST_IMAGE_PATHS

然后我上传 csv,其中包含图像的标签和名称(与文件夹相同但不按顺序排列)。

import pandas as pd
import numpy as np
data1 = pd.read_csv('/content/csvnew.csv')
df = pd.DataFrame(data1)
df.shape,df.columns

现在我需要运行一个循环来选择 1 x 1 图像并将其与 csv 中的名称进行比较。如果相似,它会调整图像大小。调整大小代码可用,

for image_path in TEST_IMAGE_PATHS:
   if TEST_IMAGE_PATHS == df['names']:
     print("done") #error here: it prints nothing
  #  return False
     imgs = read_given_images("./",TEST_IMAGE_PATHS)
     points = df['labels']
     points = np.array(points)

# resizing starts

我需要有关循环的帮助。如果有人请..

【问题讨论】:

    标签: python-3.x image loops comparison


    【解决方案1】:

    很简单。首先从 csv 中选择名称并在文件夹中找到它。 你的代码:

         imgs = read_given_images("./",TEST_IMAGE_PATHS)
     points = df['labels']
     points = np.array(points)
    

    改成:

    imgs = read_given_images("/content/human_detection_images",df.names.values)
    points = df['labels'].values
    points = np.array(points)

    这样图像和点将被一起拾取。

    【讨论】:

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