繁体   English   中英

通过保留原始图像大小来调整图像中的ROI大小

[英]Resize ROI in an image by mantaining original image size

我有这个测试图像:

src

我要实现的是减少内部ROI(文本区域),但要保留原始图像的大小。

像这样:

src_dest

如果比较两个图像,则它们具有相同的尺寸。 ROI也应该居中。

我使用OpenCv和Python。

谢谢

我将roi大小调整为一半,然后附加到图像上,有关更多信息,请参见代码:

import numpy as np
import cv2

image = cv2.imread("1.png")

print(image.shape)
h = image.shape[0]
w = image.shape[1]

center_x = int(w/2)
center_y = int(h/2)

#get the roi, suppose the roi is in the center of the image
roi = image[center_y-50:center_y+50,center_x-140:center_x+140,:].copy() 
roi_h = roi.shape[0]
roi_w = roi.shape[1]

resize_roi = cv2.resize(roi,(int(roi_w/2),int(roi_h/2)))
print(resize_roi.shape)

#delete the old roi
image[center_y-50:center_y+50,center_x-140:center_x+140,:] = 255

#append the resize_roi
image[center_y-int(50/2):center_y+int(50/2),center_x-int(140/2):center_x+int(140/2),:] = resize_roi

cv2.imshow("Image", image)
cv2.imshow("roi", roi)
cv2.imshow("resize_roi", resize_roi)
cv2.waitKey(0)

投资回报率

在此处输入图片说明

调整投资回报率

在此处输入图片说明

具有尺寸roi的图像

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM