-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathRegistration.py
74 lines (57 loc) · 2.09 KB
/
Registration.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
import numpy as np
import cv2
cap = cv2.VideoCapture('videofu.avi')
ret, frame = cap.read()
#gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
if ret==True:
Median=np.median(frame)
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(5,5))
cap = cv2.VideoCapture('videofu.avi')
Frame_width=int(cap.get(3))
Frame_hight=int(cap.get(4))
Frame_rate=int(cap.get(5))
fr=0.00
alpha=1.0
bgimg=cv2.imread("background1.jpg")
img2=cv2.imread('soccer_field_1_1800x1146.png')
B=np.zeros([Frame_hight,Frame_width,3])
cv2.namedWindow("normImg",cv2.WINDOW_OPENGL)
cv2.namedWindow("Frame",cv2.WINDOW_OPENGL)
H=np.matrix([[1.35145457e+01,3.19216300e+01,-2.56730457e+04],[6.29048034e-01,5.63744283e+01,-1.00889970e+04],[3.11140148e-04,3.75316123e-02,1.00000000e+00]])
while(cap.isOpened()):
ret, frame = cap.read()
if ret == True:
objects=frame-bgimg
objects[objects<Median]=255
objects=np.absolute(255-objects)
# objects[objects<Median/2]=0
# objects[objects>=Median/2]=255
# objects=cv2.cvtColor(objects, cv2.COLOR_BGR2GRAY)
#
# objects[objects<Median/3]=0
# objects[objects>=Median/3]=255
# objects = cv2.morphologyEx(objects, cv2.MORPH_CLOSE, kernel)
objects = cv2.morphologyEx(objects, cv2.MORPH_OPEN, kernel)
objects = cv2.dilate(objects,kernel,iterations = 1)
# objects[:,:,0]=objects[:,:,0]*4
# objects[:,:,2]=objects[:,:,2]*4
# objects[objects<Median]=0
Newimage=np.zeros([img2.shape[0],img2.shape[1],3])
Newimage=cv2.warpPerspective(objects,H,(img2.shape[1],img2.shape[0]))
Newimage=Newimage+img2
cv2.imshow('normImg', Newimage)
# Mm=cv2.moments(objects)
# m00=Mm['m00']
# m01=Mm['m01']
# m10=Mm['m10']
# posX = m10 / m00;
# posY = m01 / m00;
# print posY," ",posX
cv2.imshow('Frame', frame)
#cv2.imwrite("wwwww.jpg",objects)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv2.destroyAllWindows()