I have a similar question as here. I have a ROI which I want to update after rotating the main image. This is what I've done so far without success:
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')
but it throws:
(-215:Assertion failed) scn == m.cols || scn + 1 == m.cols in function 'cv::transform'
The main image is a 160 x 96 pixels gray scale image. As I've understood from the docs of opencv The function cv::transform performs the matrix transformation of every element of the array src and stores the results in dst. I don't know where the problem lies as the accepted answer of the linked question suggests doing this to get four points corresponding to the rect
in the rotated image.