saimj7 / People-Counting-in-Real-Time

People Counting in Real-Time with an IP camera.
MIT License
528 stars 263 forks source link

Threading not working on Raspberry Pi #42

Closed JAOT closed 1 year ago

JAOT commented 2 years ago

Hello! The system works, but I'd like to improve the performance, as when transitioning between states, there are a couple of seconds where the system freezes, most visible in "Detecting", where basically all frames are lost and unless the person moves really slowly, the system just doesn't register the person. And most times, it does not.

By activating threading, with an IP camera: using the IP, it gets stuck at :

python Run.py --prototxt mobilenet_ssd/MobileNetSSD_deploy.prototxt --model mobilenet_ssd/MobileNetSSD_deploy.caffemodel
[INFO] Starting the live stream..

Using the ip with video at the end, this more verbose happens:

python Run.py --prototxt mobilenet_ssd/MobileNetSSD_deploy.prototxt --model mobilenet_ssd/MobileNetSSD_deploy.caffemodel
[INFO] Starting the live stream..
[ERROR:0@3.717] global /tmp/pip-wheel-efxaz4j7/opencv-python_bedc0fac27944da0921e079da44d32bf/opencv/modules/videoio/src/cap.cpp (164) open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.5.5) /tmp/pip-wheel-efxaz4j7/opencv-python_bedc0fac27944da0921e079da44d32bf/opencv/modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): http://192.168.1.95:4747/video in function 'icvExtractPattern'

And using the camera module:

python Run.py --prototxt mobilenet_ssd/MobileNetSSD_deploy.prototxt --model mobilenet_ssd/MobileNetSSD_deploy.caffemodel
[INFO] Starting the live stream..
[ WARN:0@2.908] global /tmp/pip-wheel-efxaz4j7/opencv-python_bedc0fac27944da0921e079da44d32bf/opencv/modules/videoio/src/cap_v4l.cpp (889) open VIDEOIO(V4L2:/dev/video0): can't open camera by index

Again, everything works if threading is set at False, but performance with a Raspberry Pi is poor. I tried to add cv2.waitKey(250) at line 89 so that there would be less frames captured, but I am not sure this could be a good approach, as faster moving people could be missed.

Is there a better way to control the number of frames the camera captures?

Thanks.

saimj7 commented 2 years ago

Hi, haven't worked with a rpi, unfortunately no idea on tweaking the threading performance on it :/ Instead of capturing all the frames, we could try dropping some every now and then but as you said the accuracy would be low

Have you tried setting url = -1 for usb camera when using threading?

JAOT commented 2 years ago

I am using URL = 0, because I am using the camera module, but can try - 1. I was unaware of that option, even after reading the articles.

Using it, I get stuck at "Starting the live stream." with threading on.

What would be the best way to drop every odd frame? That might be enough, despite being a significant delay. Using a time based approach might not be ideal in this regard.

saimj7 commented 1 year ago

@JAOT Sorry, have you figured out a solution? What I meant with dropping frames is passing in the argument --skip-frames e.g., --skip-frames 30 to increase the processing time and also the frames per second, the accuracy could decrease though

JAOT commented 1 year ago

I did not. The raspberry pi, try as I might, is not up to the task. After multiple attempts, with smaller frames, color simplification, there isn't a possibility to make this work in such a device.