【问题标题】:Pixelate ROI bounding box and overlay it on original image using OpenCV像素化 ROI 边界框并使用 OpenCV 将其覆盖在原始图像上
【发布时间】:2020-05-03 21:49:41
【问题描述】:

让我们直截了当。

我有一个私人项目使用 open-cv 中的边界框来阻止或像素化图像,类似于审查图像,灵感来自这篇论文:

https://www.researchgate.net/publication/325746502_Seamless_Nudity_Censorship_an_Image-to-Image_Translation_Approach_based_on_Adversarial_Training

我找到了使用 Keras 对审查区域进行分类的方法,但仍然不知道如何使用边界框对分类区域进行像素化,并将其叠加到原始图像上。任何帮助表示赞赏。

这是我想要做的过程的例子:

【问题讨论】:

  • 你能添加一个输入和预期的输出图像吗?你看过how to pixelate image吗?
  • 感谢您的回复,但是,我仍然没有找到仅对从边界框分类的区域进行像素化并覆盖它的过程

标签: python opencv tensorflow image-processing keras


【解决方案1】:

一种简单的方法是使用 Numpy 切片提取 ROI,像素化,然后将其粘贴回原始图像。我将使用how to pixelate image using OpenCV in Python? 中的像素化技术。这是一个简单的例子:


要提取的输入图像和 ROI

提取的投资回报率

像素化投资回报率

结果

代码

import cv2

def pixelate(image):
    # Get input size
    height, width, _ = image.shape

    # Desired "pixelated" size
    h, w = (16, 16)

    # Resize image to "pixelated" size
    temp = cv2.resize(image, (w, h), interpolation=cv2.INTER_LINEAR)

    # Initialize output image
    return cv2.resize(temp, (width, height), interpolation=cv2.INTER_NEAREST)

# Load image
image = cv2.imread('1.png')

# ROI bounding box coordinates
x,y,w,h = 122,98,283,240

# Extract ROI
ROI = image[y:y+h, x:x+w]

# Pixelate ROI
pixelated_ROI = pixelate(ROI)

# Paste pixelated ROI back into original image
image[y:y+h, x:x+w] = pixelated_ROI

cv2.imshow('pixelated_ROI', pixelated_ROI)
cv2.imshow('image', image)
cv2.waitKey()

注意: ROI边界框坐标是使用how to get ROI Bounding Box Coordinates without Guess & Check中的脚本找到的。对于您的情况,我假设您已经拥有cv2.boundingRect 获得的x,y,w,h 边界框坐标。

【讨论】:

  • 但是我还有另一个问题,根据这个问题,如果我想从我的分类器猜测的(来自 Keras)的边界框中像素化图像,而不是从预处理的边界框?
  • 我假设你已经有了边界框坐标,如果你有来自 Keras 的边界框,这意味着你有坐标
猜你喜欢
  • 2014-05-01
  • 2019-05-17
  • 1970-01-01
  • 1970-01-01
  • 2015-07-12
  • 2018-04-27
  • 2016-03-24
  • 2021-03-03
  • 2012-12-02
相关资源
最近更新 更多