-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHoMG.py
102 lines (65 loc) · 1.74 KB
/
HoMG.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import numpy as np
import cv2
import math
#sd
def normalize(img):
strips = []
height, width = img.shape[:2]
#a = 0.005;
for i in range(height):
rowWidth = getRowWidth(i);
#rowWidth = math.floor(rowWidth);
if ((i+rowWidth)<height):
strips.append(img[i:i+rowWidth,:,:]);
else:
break;
return strips;
def getRowWidth(i):
a = 0.005;
rowWidth = 1 + 15*(1-math.exp(-1*a*i));
rowWidth = math.floor(rowWidth);
return rowWidth;
def getSobelDerivative(strips):
N = 10;
sobelX = [];
sobelY =[];
orientation = [];
magnitude = [];
for strip in strips:
x_deri = cv2.Sobel(strip,cv2.CV_64F,1,0,ksize=5)
y_deri = cv2.Sobel(strip,cv2.CV_64F,1,0,ksize=5)
sobelX.append(x_deri);
sobelY.append(y_deri);
O = N*(np.arctan2(y_deri,x_deri) + math.pi)/(2*math.pi);
orientation.append(O);
M = np.sqrt(x_deri**2+y_deri);
magnitude.append(M);
return sobelX,sobelY,orientation,magnitude;
# def computeOrientation(sobelX,sobelY):
# orientations = [];
# N = 10;
# i =0;
# for x in sobelX:
# y = sobelY[i];
# O = N*(np.arctan2(y,x) + math.pi)/(2*math.pi);
# i = i + 1;
def computeMovingGradient(img,keyframes):
T1 = 1; #Tune these variables
T2 = 1; ##""
stripsImg = normalize(img);
keyframeStrips = [];
sobelX_img,sobelY_img = getSobelDerivative(stripsImg);
sobel_img = np.sqrt(sobelX_img**2+sobelY_img**2);
for frame in keyframes:
strips = normalize(frame);
keyframeStrips.append(strip);
#Main Program Starts here........
#Constants..........
s = 1;
wp = 3;
#...................
img = cv2.imread('1.bmp');
strips = normalize(img);
sobelX,sobelY,orientation,magnitude = getSobelDerivative(strips);
#computeOrientation(sobelX,sobelY)
# height, width = img.shape[:2];