-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathestimateFeatureTranslation.py
More file actions
executable file
·65 lines (32 loc) · 1.12 KB
/
estimateFeatureTranslation.py
File metadata and controls
executable file
·65 lines (32 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 19 08:28:12 2018
@author: cis581
"""
import numpy as np
from getFeatures import getFeatures
import cv2
from matplotlib import pyplot as plt
from interp2 import interp2
from scipy import signal
def transformFeatures(startX, startY):
p0 = np.zeros((1,1,2),dtype = 'float32')
p0[:, :, 0] = startY
p0[:, :, 1] = startX
return p0
def recoverFeaures(p0):
startX = p0[:, :, 1]
startY = p0[:, :, 0]
return startX, startY
def estimateFeatureTranslation(startX, startY, Ix, Iy, img1, img2):
im1 = img1.dot([0.587, 0.114, 0.299])
im2 = img2.dot([0.587, 0.114, 0.299])
# Parameters for lucas kanade optical flow
lk_params = dict( winSize = (15,15),
maxLevel = 2,
criteria = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 0.03))
p0 = transformFeatures(startX, startY)
p1, st, err = cv2.calcOpticalFlowPyrLK(im1.astype('uint8'), im2.astype('uint8'), p0, None, **lk_params)
oriX_opt, oriY_opt = recoverFeaures(p1)
return oriX_opt, oriY_opt