gpt4 book ai didi

c++ - 使用 Opencv 模糊矩形中的内容

转载 作者:太空宇宙 更新时间:2023-11-03 20:52:00 26 4
gpt4 key购买 nike

在下面的矩形函数中,绘制了矩形。

// Draw the predicted bounding box
void drawPred(int classId, float conf, int left, int top, int right, int bottom, Mat& frame)
{
//Draw a rectangle displaying the bounding box
rectangle(frame, Point(left, top), Point(right, bottom), Scalar(255, 178, 50),LINE_4);

//bluring region
cout << frame;

//Get the label for the class name and its confidence
string label = format("%.2f", conf);
if (!classes.empty())
{
CV_Assert(classId < (int)classes.size());
label = classes[classId] + ":" + label;
}

//Display the label at the top of the bounding box
int baseLine;
Size labelSize = getTextSize(label, FONT_ITALIC, 0.5, 1, &baseLine);
top = max(top, labelSize.height);
putText(frame, label, Point(left, top), FONT_ITALIC, 0.5, Scalar(255, 255, 255), 1);
}

这里的frame是一个多数组的图片。Point(left, top) 是矩形的左上角点。
我想以模糊的形式审查这个矩形中的所有内容。由于我是Python编程出身,定义这些矩形的数组有点难。如果你能帮助我,那就太好了。非常感谢你,并致以最诚挚的问候。

最佳答案

这是与@HansHirse 的回答等价的 Python。思路是一样的,只是我们使用 Numpy 切片来获取 ROI

import cv2

# Read in image
image = cv2.imread('1.png')

# Create ROI coordinates
topLeft = (60, 40)
bottomRight = (340, 120)
x, y = topLeft[0], topLeft[1]
w, h = bottomRight[0] - topLeft[0], bottomRight[1] - topLeft[1]

# Grab ROI with Numpy slicing and blur
ROI = image[y:y+h, x:x+w]
blur = cv2.GaussianBlur(ROI, (51,51), 0)

# Insert ROI back into image
image[y:y+h, x:x+w] = blur

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

关于c++ - 使用 Opencv 模糊矩形中的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58163739/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com