Ask Your Question
0

Passengers counting in car using opencv

asked Jan 20 '0

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?

Preview: (hide)

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 (Jan 20 '0)edit
1

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

supra56 gravatar imagesupra56 (Jan 20 '0)edit
1

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

holger gravatar imageholger (Jan 20 '0)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 (Jan 20 '0)edit

2 answers

Sort by » oldest newest most voted
0

answered Jan 30 '0

supra56 gravatar image

updated Jan 30 '0

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.

Preview: (hide)
0

answered Mar 29 '0

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!

Preview: (hide)

Question Tools

Stats

Asked: Jan 20 '0

Seen: 1,625 times

Last updated: Mar 29 '20