【发布时间】:2018-11-02 11:03:30
【问题描述】:
我有一张图片,例如Width=999 和 Height=767。我知道我的投资回报率的轮廓,并使用rect=cv2.minAreaRect() 来获得rotated rectangle 周围的CenterPosition、Width、Height 和Angle。现在我需要将图像调整为另一个图像的大小,例如Width=4096 和 Height=2160。到目前为止,我正在使用cv2.resize() 这样做。
我现在的问题是,当然我的矩形的boxPoints 也发生在其他地方,rect 中的数据关于CenterPosition、Width、Height 和Angle 的@987654340 @ 现在调整大小的 ROI 周围没有更新,因此是错误的。我尝试了不同的解决方法,但还没有找到任何解决方案。
这是我的代码:
import numpy as np
import cv2
#Create black image
img = np.zeros((767, 999, 3), np.uint8)
#Turn ROI to white
cv2.fillConvexPoly(img, np.array(ROI_contour), (255, 255, 255))
#Get Width, Height, and Angle of rectangle around ROI
rect = cv2.minAreaRect(np.array(ROI_contour))
#Draw rotated rectangle in red
box = cv2.boxPoints(rect)
box = np.int0(box)
cv2.drawContours(img,[box], 0, (0,0,255), 1)
#Resize img to new size
img_resized = cv2.resize(img, (4096, 2160), interpolation=cv2.INTER_AREA)
这是img 例如可能看起来像:
在调整大小之前,带有白色 ROI 的 img - ROI 的中心位置、宽度、高度和角度由 rect 知道。
如何获得调整后 ROI 的新宽度、高度和角度?
【问题讨论】:
-
h(new) / h(old) 和 w(new) / w(old) 会给你新的值,对吧?这里有基础数学!
标签: python opencv image-processing