Ask Your Question
0

Passengers counting in car using opencv

asked 2020-01-20 01:04:57 -0600

Huma gravatar image

Hi All,

I'm working on a project where a camera is installed and a pic is taken after the door is closed. So i need to identify the number of people seated in the car using the image captured. Is there any already trained models i could use to achieve this? Should i go for face detection to count the number of people or human detection? what should be the right approach?

edit retag flag offensive close merge delete

Comments

You most likely want to use a cnn for this. Search for a pretrained model for detecting person and cars. Then use the dnn module of opencv to evaluate the model. There a lot of tutorials out there.

holger gravatar imageholger ( 2020-01-20 04:44:36 -0600 )edit
1

@Huma. Where will you camera in vehicle(depending on vehicle)?

supra56 gravatar imagesupra56 ( 2020-01-20 06:56:54 -0600 )edit
1

Hah! - good question - on this your model selection depends.

holger gravatar imageholger ( 2020-01-20 07:15:48 -0600 )edit

I was going to ask him where will he puts camera. As you noticed driver seat and front passenger seat both have on headrests too. It is too dark inside vehicle or not.

supra56 gravatar imagesupra56 ( 2020-01-20 09:11:05 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2020-01-30 09:15:05 -0600

supra56 gravatar image

updated 2020-01-30 09:17:19 -0600

Here is code for ARM:

#1/usr/bin/python3.7.3
#OpenCV 4.2, Raspberry pi 3/3b+, 4b, Buster ver 10
#Date 30th January, 2020

import cv2 as cv

face_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml') 

cap = cv.VideoCapture(1)
font = cv.FONT_HERSHEY_SIMPLEX
org = (5, 25)
color = (255, 0, 0)

while cap.isOpened(): 

    # reads frames 
    ret, img = cap.read() 

    # convert to gray scale 
    gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) 

    # Detects faces
    faces = face_cascade.detectMultiScale(gray, 1.1, 5)

    #print("Number of {0} faces!".format(len(faces)))
    cv.putText(img, "Number of {0} faces!".format(len(faces)),
               org, font, 1, color, 2)

    cv.imshow('img',img) 

    # Wait for Esc key to stop 
    k = cv.waitKey(10) 
    if k == 27: 
        break

cap.release() 
cv.destroyAllWindows()

if you needed picamera. I'll be happier to help.

edit flag offensive delete link more
0

answered 2020-03-29 05:24:53 -0600

ComputerVisionary gravatar image

The open source world is moving massively to deep learning approaches without considering the "old school" methods are (still in 2020) the best trade-off in speed/accuracy for a lot of application (specially on ARM devices). I can suggest to use an earlier versions of OpenCV to train the cascades, I'm still using the traincascade in Opencv 2.4.10 and it is still perfectly working and suitable for OpenCV 3 and 4. More here:

Detecting people in cars it's tricky mostly due to lighting condition. Standard cascades in opencv won't work, you should try training custom cascades by yourself.

Regards!

edit flag offensive delete link more

Question Tools

Stats

Asked: 2020-01-20 01:04:57 -0600

Seen: 1,526 times

Last updated: Mar 29 '20