forked from geekysethi/pedestrian-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
training.py
66 lines (50 loc) · 1.57 KB
/
training.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
import cv2
import numpy as np
import glob
from matplotlib import pyplot as plt
import backgroundModelFunctions
import backgroundModel
# import tqdm
import _pickle as cpickle
import time
# np.set_printoptions(threshold=np.inf)
path = np.sort(glob.glob('/home/geekysethi/Desktop/pedestrain-detection/Crowd_PETS09/S0/Background/View_001/Time_13-06/*.jpg'))
firstFrame = cv2.imread(path[0],0)
bgModel=backgroundModel.backgroundModel(firstFrame,1,.7)
kernel = np.ones((3,3),np.uint8)
start_time=time.clock()
alpha=1
count=0
for i in path[20:120]:
firstFrame = cv2.imread(path[count],0)
count+=1
currentImage=cv2.imread(i,0)
binaryImage=backgroundModelFunctions.change_detection(firstFrame,currentImage,15)
bgModel.update_alpha(alpha)
bgModel.updateBackgroundModel(currentImage,binaryImage)
print(bgModel.alpha)
alpha+=1
print(i)
# plt.subplot(2,2,1)
# plt.imshow(currentImage,cmap='gray')
# plt.subplot(2,2,2)
# plt.imshow(binaryImage,cmap='gray')
# plt.subplot(2,2,3)
# plt.imshow(bgModel.meanImage,cmap='gray')
# plt.subplot(2,2,4)
# plt.imshow(bgModel.varianceImage,cmap='gray')
# plt.pause(0.005)
print('Total time: '+str(time.clock()-start_time))
cv2.imshow("current Image",binaryImage)
cv2.imshow('meanImage',bgModel.meanImage)
cv2.imshow('varianceImage',bgModel.varianceImage)
print('='*80)
print("Dumping Data")
pickle_out1=open('meanImage.pickle','wb')
cpickle.dump(bgModel.meanImage,pickle_out1)
pickle_out2=open('VarianceImage.pickle','wb')
cpickle.dump(bgModel.varianceImage,pickle_out2)
print('Data Dumped')
print('='*80)
cv2.waitKey(0)
cv2.destroyAllWindows()