-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinalProject.py
More file actions
70 lines (70 loc) · 2.81 KB
/
FinalProject.py
File metadata and controls
70 lines (70 loc) · 2.81 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
66
67
68
69
70
import cv2
import matplotlib.pyplot as plt
from imageai.Detection import VideoObjectDetection
import os
camera = "newinput_Trim.mp4"
# execution = os.getcwd()
color_index = {'motorbike' : 'red'}
resized = True
count = 0
import FinalTriple
import FinalHelmet
def bikedetect(frame_number,output_array,output_count,returned_frame):
print("Bike Frame : ",frame_number)
if 'motorbike' in output_count and output_count['motorbike'] > 0 :
# plt.rcParams["figure.figsize"]=(25,3)
# plt.clf()
#
this_colors=[]
labels=[]
sizes=[]
counter=0
#
for eachItem in output_count:
counter+=1
labels.append(eachItem+" = "+str(output_count[eachItem]))
sizes.append(output_count[eachItem])
this_colors.append(color_index[eachItem])
#
global resized
global count
#
if (resized == False):
manager = plt.get_current_fig_manager()
manager.resize(w=500,h=1000)
resized = True
for item in output_array:
x1 = item['box_points'][0]
y1 = item['box_points'][1]
x2 = item['box_points'][2]
y2 = item['box_points'][3]
if(y2-y1 > 150 and y2>150 and (x2-x1)>50):
new_frame = returned_frame[max(int(y1-(y2-y1)*0.9),0):y2,x1:x2]
helmet_image = returned_frame[max(int(y1/4-(y2/4-y1/4)*(0.8/4)),0):y1,x1:x2]
bike_image = returned_frame[y1:y2,x1:x2]
count+=1
cv2.imwrite("OutPut/Finalnew/Bike/bike-"+str(count)+".jpg",bike_image)
cv2.imwrite("OutPut/Finalnew//Rider/rider-" + str(count) + ".jpg", helmet_image)
cv2.imwrite("OutPut/Finalnew/Full/full-"+str(count)+".jpg",new_frame)
plt.title("frame number " + str(frame_number))
plt.imshow(new_frame)
print("Going for Helmet detection")
FinalHelmet.main(count)
print("Going for Triple raid detection")
FinalTriple.main(count)
plt.pause(0.1)
detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath("yolov3.pt")
detector.loadModel()
custom_bikes = detector.CustomObjects(motorbike=True)
plt.show()
print("Starting The Bike Detection : ")
detector.detectObjectsFromVideo(custom_objects=custom_bikes,
input_file_path="./InputVideos/RoadVideo02.mp4",
output_file_path="OutPut/newoutput/bikeride",
frames_per_second=1,
per_frame_function=bikedetect,
minimum_percentage_probability=70,
return_detected_frame=True,
frame_detection_interval=20)