car detection in video as well as from the front camera

hey so this is the project i didnt get he satisfied output any one please try and help me out. i can guide you with the explaination

for the xml file
.................................................................................................................................
.................................................................................................................
video:https://www.youtube.com/watch?v=d4L1Pte7zVc
just to check


import cv2
#use videocapture for online detection of cars
#video = cv2.VideoCapture(0)

video = cv2.VideoCapture("tesla_car_detect.mp4")
classifier_file ='car_detector.xml'
car_tracker = cv2.CascadeClassifier(classifier_file)

#1st approch
# Read until video is completed
while (video.isOpened()):
    # Capture frame-by-frame
    ret, frame = video.read()
    if ret == True:
        
        # Display the resulting frame
        cars  = car_tracker.detectMultiScale(frame)
        cv2.imshow('car detector machine',frame)
        for (x,y,w,h) in cars:
            cv2.rectangle(frame, (x,y),(x+w,y+h), (0,0,255),2)
    # Break the loop
    else:
        break

#2nd approch most effective approch
'''
while True:

    (read_succes,frame) = video.read()
   

    if read_succes:
        grayscale_frame = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    else:
        break
    cars  = car_tracker.detectMultiScale(grayscale_frame)
    print(cars)
    

    for (x,y,w,h) in cars:
        cv2.rectangle(frame, (x,y),(x+w,y+h), (0,0,255),2)

        cv2.imshow('frame',frame)


'''
if cv2.waitKey(25) & 0xFF == ord('q'):
    video.release()
# Closes all the frames
    cv2.destroyAllWindows()
    print ("code completed")

Comments

Popular posts from this blog

environment creation on python

scatterplot/ violon plot /histogram /boxplot

Pcb Fault Detection(Deep Learning Technique)