Python: Detect camera shift angle comparing the reference image and live image taken from a camera

Viewed 1302

For a project work, I need to find the camera shift angle using a reference image. I have fixed a CC camera and taken an image as a reference. On a regular interval, I need to check if anyone had changed the camera position. if yes, need to find the angle of camera shift. How can I achieve this?

Sample image2

Sample image

The images provided are just samples. Actually, the camera may be in an outdoor scenario. It may be fixed in a front gate or similar. Need to find if anybody has changed the camera position. Any camera tampering condition by shifting the camera position needs to be found. Can anyone help me to solve this? Any ideas?

def find_angle(frame): frame = cv2.cvtColor(np.array(frame), cv2.COLOR_BGR2GRAY) referenceImage = cv2.imread(lux.camera_specs['data'][cameras]['reference_image']) referenceImage = cv2.resize(referenceImage, (480, 320)) referenceImage = cv2.cvtColor(referenceImage, cv2.COLOR_BGR2GRAY) referenceImage = np.float32(referenceImage) liveViewImage = np.float32(frame) shift = cv2.phaseCorrelate(referenceImage, liveViewImage) print (shift) fitGrade = shift[1] angle = math.sqrt((shift[0][0] * shift[0][0]) + (shift[0][1] * shift[0][1])) return fitGrade, angle

0 Answers
Related