旋转图像后更新CV ::矩形

问题描述 投票:0回答:1

我有一个类似的问题作为here。我有我想要的主图像旋转后更新的投资回报率。这是我迄今所做的没有成功:

cords = ['0', '0.175', '0.46875', '0.125', '0.5875']
x = float(cords[1]) * 160
y = float(cords[2]) * 96
w = float(cords[3]) * 160
h = float(cords[4]) * 96
x = x - (w / 2)
y = y - (h / 2)
rect = np.float32([[x, y],
                   [x + w, y],
                   [x + w, y + h],
                   [x, y + h]])
for angle in range(-10, 10, 2):
    rot = cv2.getRotationMatrix2D((160 / 2, 96 / 2), angle, 1.0)
    trect = cv2.transform(rect, rot)
    print('Transformed rectangle: ', trect)
    print('done')

但它抛出:

(-215:Assertion failed) scn == m.cols || scn + 1 == m.cols in function 'cv::transform'

主图像是160×96像素的灰度图像。正如我从OpenCV的函数Cv的文档理解::变换执行所述阵列的src每个元素的矩阵变换并存储在DST的结果。我不知道问题出在哪里作为链接的问题的答案接受建议这样做是为了获得相应的旋转图像中的rect四点。

python opencv
1个回答
0
投票

这不是在文件中明确,但它需要一个numpy阵列类似下面的工作:

rect = np.array([[[x, y]],
                 [[x + w, y]],
                 [[x + w, y + h]],
                 [[x, y + h]]])
© www.soinside.com 2019 - 2024. All rights reserved.