像素化ROI边界框,并使用OpenCV将其覆盖在原始图像上 [英] Pixelate ROI bounding box and overlay it on original image using OpenCV

查看:111
本文介绍了像素化ROI边界框,并使用OpenCV将其覆盖在原始图像上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让它变得简单明了.

我有一个私人项目来使用open-cv中的边界框来阻止或像素化图像,例如检查图像,这受本文启发:

I have private project to block or pixelate image using boundary box in open-cv, something like censoring image, inspired from this paper:

https://www.researchgate.net/publication/325_502________ers_ships_ship_on_ers_ship_on_ers_ships-ships_ships_ships_ships-anmless-

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

I have found the way to classify the area of censor using Keras, but still don't know the way how to use the boundary box to pixelate the classified area, and overlay it to original image. Any help are appreciated.

这是我要执行的过程的示例:

This is the example of the process that I want to do:

推荐答案

一种简单的方法是使用Numpy切片,像素化来提取ROI,然后将其粘贴回原始图像中.我将使用在如何使用OpenCV对图像进行像素化中找到的像素化技术Python?.这是一个简单的示例:

A simple method is to extract the ROI using Numpy slicing, pixelate, then paste it back into the original image. I will be using the pixelation technique found in how to pixelate image using OpenCV in Python?. Here's a simple example:

要提取的输入图像和ROI

Input image and ROI to be extracted

提取的投资回报率

Extracted 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()

注意:使用

Note: The ROI bounding box coordinates were found by using the script in how to get ROI Bounding Box Coordinates without Guess & Check. For your case, I will assume that you already have the x,y,w,h bounding box coordinates obtained by cv2.boundingRect.

这篇关于像素化ROI边界框,并使用OpenCV将其覆盖在原始图像上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆