import cv2

video=cv2.VideoCapture(r'C:\Users\ISHITA\Desktop\ML project\UEM_PROJECT_COM\pedestrian.mp4')

#pre trained pedestrian and car classifier
car_tracker_file=(r'C:\Users\ISHITA\Desktop\ML project\UEM_PROJECT_COM\car.xml')
pedestrian_tracker_file=(r'C:\Users\ISHITA\Desktop\ML project\UEM_PROJECT_COM\pedestrian.xml')

#create car n pedestrian classifier
car_tracker=cv2.CascadeClassifier(car_tracker_file)
pedestrian_tracker=cv2.CascadeClassifier(pedestrian_tracker_file)

#run forever untill car stop
while True:
    
    (read_successful,frame)=video.read()
  
    gr_frame=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
   
    #detect cars n pedestrian
    cars=car_tracker.detectMultiScale(gr_frame)
    pedestrians=pedestrian_tracker.detectMultiScale(gr_frame)

    #draw rectangle around cars
    for(x,y,w,h) in cars:
        cv2.rectangle(frame,(x+1,y+2),(x+w,y+h),(255,0,0),2)
        cv2.rectangle(frame,(x,y),(x+w,y+h),(0,0,255),2)
    
    #draw rectangle around pedestrian
    for(x,y,w,h) in pedestrians:
        cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,255),2)

    #display
    cv2.imshow('car n pedestrians',frame)
    key = cv2.waitKey(1)
    
    #stopping condition
    if key == 83 or key== 115:
        break

# release the VideoCapture object
video.release()
    
print('Press "s" to stop')

print('Hey!')

[((3, 6, 3, 92), 'cv2.VideoCapture', 'cv2.VideoCapture', ({(3, 23, 3, 91): '"""C:\\\\Users\\\\ISHITA\\\\Desktop\\\\ML project\\\\UEM_PROJECT_COM\\\\pedestrian.mp4"""'}, {}), "(\n    'C:\\\\Users\\\\ISHITA\\\\Desktop\\\\ML project\\\\UEM_PROJECT_COM\\\\pedestrian.mp4')", False, 'import cv2\n'), ((10, 12, 10, 51), 'cv2.CascadeClassifier', 'cv2.CascadeClassifier', ({(10, 34, 10, 50): 'car_tracker_file'}, {}), '(car_tracker_file)', False, 'import cv2\n'), ((11, 19, 11, 65), 'cv2.CascadeClassifier', 'cv2.CascadeClassifier', ({(11, 41, 11, 64): 'pedestrian_tracker_file'}, {}), '(pedestrian_tracker_file)', False, 'import cv2\n'), ((18, 13, 18, 51), 'cv2.cvtColor', 'cv2.cvtColor', ({(18, 26, 18, 31): 'frame', (18, 32, 18, 50): 'cv2.COLOR_BGR2GRAY'}, {}), '(frame, cv2.COLOR_BGR2GRAY)', False, 'import cv2\n'), ((34, 4, 34, 41), 'cv2.imshow', 'cv2.imshow', ({(34, 15, 34, 34): '"""car n pedestrians"""', (34, 35, 34, 40): 'frame'}, {}), "('car n pedestrians', frame)", False, 'import cv2\n'), ((35, 10, 35, 24), 'cv2.waitKey', 'cv2.waitKey', ({(35, 22, 35, 23): '1'}, {}), '(1)', False, 'import cv2\n'), ((26, 8, 26, 60), 'cv2.rectangle', 'cv2.rectangle', ({(26, 22, 26, 27): 'frame', (26, 28, 26, 37): '(x + 1, y + 2)', (26, 38, 26, 47): '(x + w, y + h)', (26, 48, 26, 57): '(255, 0, 0)', (26, 58, 26, 59): '(2)'}, {}), '(frame, (x + 1, y + 2), (x + w, y + h), (255, 0, 0), 2)', False, 'import cv2\n'), ((27, 8, 27, 56), 'cv2.rectangle', 'cv2.rectangle', ({(27, 22, 27, 27): 'frame', (27, 28, 27, 33): '(x, y)', (27, 34, 27, 43): '(x + w, y + h)', (27, 44, 27, 53): '(0, 0, 255)', (27, 54, 27, 55): '(2)'}, {}), '(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)', False, 'import cv2\n'), ((31, 8, 31, 58), 'cv2.rectangle', 'cv2.rectangle', ({(31, 22, 31, 27): 'frame', (31, 28, 31, 33): '(x, y)', (31, 34, 31, 43): '(x + w, y + h)', (31, 44, 31, 55): '(0, 255, 255)', (31, 56, 31, 57): '(2)'}, {}), '(frame, (x, y), (x + w, y + h), (0, 255, 255), 2)', False, 'import cv2\n')]