【发布时间】:2019-02-04 14:38:26
【问题描述】:
我有一个与here 类似的问题。我有一个 ROI,我想在旋转主图像后更新它。这是我迄今为止所做的没有成功:
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 x 96 像素的灰度图像。正如我从 opencv 的文档中了解到的那样函数 cv::transform 对数组 src 的每个元素执行矩阵变换,并将结果存储在 dst。我不知道问题出在哪里,因为链接问题的公认答案建议这样做以获得与旋转图像中的 rect 相对应的四个点。
【问题讨论】: