首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >填补ROI的中心

填补ROI的中心
EN

Stack Overflow用户
提问于 2022-04-27 09:19:40
回答 1查看 166关注 0票数 0

如何填充ROI,使图像被放置在ROI的中心?

ROI是用(x, y, w, h) = cv2.boundingRect(contour)找到的,我用

image = cv2.resize(input\_image, (w, h)) img2gray = cv2.cvtColor(image, cv2.COLOR\_BGR2GRAY) \_, image\_mask = cv2.threshold(img2gray, 1, 255, cv2.THRESH\_BINARY) roi = frame[y:y+h, x:x+w] roi[np.where(image\_mask)] = 0 roi += image

hw是输入图像的尺寸。

如何添加偏移量,以使ROI += image的结果与图像中所显示的一样?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-27 12:45:07

根据我的理解,您希望将调整大小的图像放在ROI的中心。

您已经获得了ROI roi = frame[y:y+h, x:x+w]

代码语言:javascript
复制
# using this as background, hence making it white
roi[:] = (255, 255, 255)

# Obtain the spatial dimensions of ROI and image
roi_h, roi_w = roi.shape[:2]
image_h, image_w = image.shape[:2]

# Calculate height and width offsets
height_off = int((roi_h - image_h)/2)
width_off = int((roi_w - image_w)/2)

# With Numpy slicing, place the image in the center of the ROI
roi[height_off:height_off+image_h, width_off:width_off+image_w] = image

我希望这能给你一个关于如何进一步推进的想法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72026292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档