python - 使用 python/opencv pandas 在集合中查找规范图像

标签 python image pandas opencv canonical-link

我有一个从视频流中捕获的大型图像数据集,我想从中提取规范数据集。例如,数据集可能由 60% 的纯背景、20% 的人背景和 20% 非常暗的图像组成。

作为一个简单的原型(prototype),我想计算每个图像的平均 RGB 并将相似的 RGB 值合并在一起,并从每个容器中随机抽样。

rgb_avg = {}
for i in img_list:
    img = cv2.imread(i)
    rgb_avg[i] = np.mean(img)
rgb_series = pd.Series(rgb_avg)
bins = pd.cut(rgb_series,bins=10)

这让我留下了一系列类别,但找不到关于如何使用这个系列并从每个箱子中随机抽样的好教程。如何将我的 RGB 系列分成 10 个 bin 并从每个 bin 中随机采样一个文件?

最佳答案

我能够通过以下方式完成它:

rgb_avg = {}
for i in img_list:
    img = cv2.imread(i)
    rgb_avg[i] = np.mean(img)
rgb_series = pd.Series(rgb_avg)
bins = pd.cut(rgb_series,bins=10)
bin_values = sorted([b.right for b in bins.unique()])
img_bins = {b : [] for b in bin_values}
for img,rgb in rgb_avg.items():
    for b in bin_values:
        if rgb <= b:
            img_bins[b].append(img)
for b in img_bins:
    img = np.random.choice(img_bins[b])
    plt.imshow(cv2.imread(img))
    plt.show()

可能不是最有效的,但它可以完成工作。

关于python - 使用 python/opencv pandas 在集合中查找规范图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45517371/

相关文章:

python - Openstack Neutron 命令工作流程

css - 在 CSS 中使用 Twitter Bootstrap 字形

python - 在 pandas 中定期获取每月的第 n 个工作日

python - 如何限制 python 程序的最大 CPU 使用率

python - 无法使用 Mixin 类扩展 python IntEnum

python - 减少不适用于 collections.defaultdict?

html - CSS:通过不使用JS的包含图像定义元素的宽度

c# - 在 WebBrowser 控件中禁用滚动

python - 数据框中行和列之间的交互

python - 需要帮助通过仅对一列进行分组来将 pandas 数据框转换为多索引。