I want to measure the rotation between two objects in two images. The second image is created by rotating the first one. I tried techniques like fitting a line but like you can see they get the same slope/angle.
Here is my code:
import cv2
import numpy as np
import matplotlib.pyplot as plt
#import imutils
img = cv2.imread("4.jpg",0)
indices = np.where(img!= [255])
coordinates = zip(indices[0], indices[1])
from scipy.optimize import curve_fit
def f(x, A, B): # this is your 'straight line' y=f(x)
return A*x + B
A,B = curve_fit(f, indices[1], indices[0])[0] # your data x, y to fit
x=np.arange(0,1000,1)
y=A*x+B
#%%
plt.plot(y)
plt.scatter(indices[1],indices[0])
plt.show()
Original image:
Original image rotated by 180°: