OpenCV Python program for Vehicle detection in a Video frame

asked 2020-10-21 01:02:27 -0500

yujy9014 gravatar image

updated 2020-10-21 04:21:07 -0500

If a vehicle is detected in this source, I want to put the vehicle detected data in the database. How can I do it?

import cv2

cap = cv2.VideoCapture(0) 
car_cascade = cv2.CascadeClassifier('cars.xml')
while True: 
# reads frames from a video 
ret, frames = 

# convert to gray scale of each frames 
gray = cv2.cvtColor(frames, cv2.COLOR_BGR2GRAY) 

# Detects cars of different sizes in the input image 
cars = car_cascade.detectMultiScale(gray, 1.1, 1) 

# To draw a rectangle in each cars 
for (x,y,w,h) in cars: 

# Display frames in a window  
 cv2.imshow('video2', frames) 

# Wait for Esc key to stop 
if cv2.waitKey(33) == 27: 

Source is here

edit retag flag offensive close merge delete


this code is doing detection only, so what do you want to save, exactly ?

berak gravatar imageberak ( 2020-10-21 02:04:43 -0500 )edit

First of all, I am just thinking about the current time

yujy9014 gravatar imageyujy9014 ( 2020-10-21 04:09:18 -0500 )edit