-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinal_Code.py
62 lines (42 loc) · 1.56 KB
/
Final_Code.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
import cv2
import os
import os.path
import sys
import tkinter as tk
from tkinter.filedialog import askopenfilename
import shutil
import os
import sys
from PIL import Image, ImageTk
print('Project Topic : Recognisation')
dirPath = "testpicture"
fileList = os.listdir(dirPath)
for fileName in fileList:
os.remove(dirPath + "/" + fileName)
fileName = askopenfilename(initialdir='C:\\Users\\admin\\Desktop\\DRONEDETEON', title='Select image for analysis ',
filetypes=[('image files', '')])
dst = "C:/Users/admin/OneDrive/Desktop/DRONEDETEON/testpicture"
shutil.copy(fileName, dst)
video_src = (fileName)
cap = cv2.VideoCapture(video_src)
bike_cascade = cv2.CascadeClassifier('two_wheeler.xml')
people_cascade = cv2.CascadeClassifier('pedestrian.xml')
car_cascade = cv2.CascadeClassifier('cars.xml')
while True:
ret, img = cap.read()
if (type(img) == type(None)):
break
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
bikes = bike_cascade.detectMultiScale(gray,1.01, 1)
people = people_cascade.detectMultiScale(gray,1.3,2)
cars = car_cascade.detectMultiScale(gray, 1.1, 1)
for (x,y,w,h) in bikes:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,215),2)
for(a,b,c,d) in people:
cv2.rectangle(img,(a,b),(a+c,b+d),(0,255,210),4)
for (x,y,w,h) in cars:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,255),1)
cv2.imshow('video', img)
if cv2.waitKey(1) == 13:
break
cv2.destroyAllWindows()