Helping small businesses deal with Covid-19 capacity restrictions with Computer Vision
Plug it, point the camera towards the inside of the bar or shop, and you'll know whether the next customer can come in or not.
Continuing on what I did last week, I wanted to come up with some other ideas to help people fight against the struggles Covid-19 pandemic and the restrictions that had come with it. So I thought that bars and shops indoors might be having trouble trying to constantly monitor the number of people inside and that it would be cool to design something to help alleviate that extra workload.
This is what I came up with:
This Raspberry-Pi-based device has its main advantage that it doesn't require any prior knowledge on the matter. It's completely "plug and play" and only has 3 "major" components:
- The box with the hardware and software and the screen (a more advanced one could be used or one with more digits but I didn't have around)
- A webcam, anyone will do, it doesn't need to have a very good resolution.
- The power supply, a smartphone one will do the job too, although it would be a good idea to have a dedicated one for Raspberry Pi.
But here below you can see some tests I did at home capturing the screen, when it detects my face it shows "1" on the counter and when it detects nothing because I cover the webcam it goes to "0".
Regarding the prices of the components that I used, the main ones are almost the same as the ones in this entry: https://achefethings.blogspot.com/2021/05/computer-vision-to-fight-against.html, this is somehwere below 100 euros for the Raspi, the camera and the power supply, and really the cables, resistances and screen display all together would be below 5 euros, so yes I would say all in all with a tight budget a lot of nice things can be done.
The software
The Raspberry Pi runs a Debian port OS, I out this little tiny script on its desktop you can see below, and then in the cmd, I had to type the following command lines to install OpenCV for Python to order the Raspberry Pi to run a script on boot.
There is one more thing that you need to have this running on your device, the haarcascades .xml files that you can find in this GitHub repository https://github.com/opencv/opencv/tree/master/data/haarcascades and by the way, you have haar_cascades classifiers for a bunch of things ranging from different features of people to cats, hand or Russian license plates.
Run script on the boot
OpenCV
import cv2
cv2.__version__
# este es el bueno
import cv2 as cv
import RPi.GPIO as GPIO
display_list = [17,27,22,10,9,11,5]
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
for pin in display_list:
GPIO.setup(pin,GPIO.OUT) # setting pins
GPIO.setup(6,GPIO.OUT) # setting dot pin
GPIO.setwarnings(True)
arrSeg = [[1,1,1,1,1,1,0],\
[0,1,1,0,0,0,0],\
[1,1,0,1,1,0,1],\
[1,1,1,1,0,0,1],\
[0,1,1,0,0,1,1],\
[1,0,1,1,0,1,1],\
[1,0,1,1,1,1,1],\
[1,1,1,0,0,0,0],\
[1,1,1,1,1,1,1],\
[1,1,1,1,0,1,1]]
vid = cv.VideoCapture(0)
while True:
ret, frame = vid.read()
gray_frame = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
haar_cascade = cv.CascadeClassifier("/home/pi/Desktop/haarcascade.xml")
faces_rect = haar_cascade.detectMultiScale(gray_frame, scaleFactor=1.1, minNeighbors=4)
for (x, y, w, h) in faces_rect:
cv.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), thickness=2)
cv.imshow("frame", frame)
if cv.waitKey(1) & 0xFF == ord("q"):
break
n_faces = len(faces_rect)
numDisplay = int(n_faces)
if numDisplay == 10:
GPIO.cleanup()
else:
GPIO.output(display_list, arrSeg[numDisplay])
vid.release()
cv.destroyAllWindows()
The hardware
- Any camera that has a USB cable
- Raspberry-Pi
- Power-supply
- 8 330 Ohm resistance
- Breadboard
- About 25 male-female jumper wires unless you are looking forward to soldering the connections
- 1 digit 7 segment screen
- 3D printed enclosure to keep it all tight and safe
And I think I am just missing the enclosure, which was designed in Fusion360, my go-to 3D modelling software as always, and printed in my good ol' reliable Ender 3 with some random PLA I had hanging around (in fact, I had many problems printing it I hope to have some time to service it soon). Down below you can see some snapshots of the 3D models in the slicer software (Ultimaker Cura).
Conclusions
It took me 3 days to build this during my free time, I had many unforeseen events happening like changing completely my design halfway through since I was not being able to establish I2C communications between the Raspberry Pi and the Arduino and so I had to opt for another approach. But after encountering and solving all these issues: oh boy, I am so happy with the result and I learnt so much from it.
I hope you enjoyed reading the entry as much I enjoyed preparing it, it's been by far the most complex thing I've done so far and I am so proud of it.
If you want to try it for yourself and you have any doubt, contact me and I'll be more than happy to respond to your questions.
Hope you like it,
Pablo
f
Comments
Post a Comment