During the time of the COVID - 19, it is a little indisposed but we need to wear a mask in public places for our health. In the shop, mall, or other high-volume public places, the managers sometimes have trouble observing whether people wearing masks. To see a man whether it is wearing a mask is easy for us, but if we give it to Jetson Nano, graphics capture and edge computing with AI, it will be a very interesting and socially valuable task.
Hence, in this project, we will use the reComputer J1010 to implement industrial- level crowd face mask monitoring based on a nice tool - MaskCam. Meanwhile, you can also choose reComputer J1020 which also equips the Jetson Nano module.
MaskCam was developed by Berkeley Design Technology, Inc. (BDTI) and Tryolabs S.A., with development funded by NVIDIA. MaskCam is offered under the MIT License. For further information about MaskCam, please refer to the report from BDTI.
Getting StartedHardware Requirement
- reComputer J1010 (JetPack 4.6)
- 7-inch hdmi monitor and HDMI cable
- USB Docking Station
- Mouse and Keyboard
- 5V 4A Power Adapter
- USB Camera
- Ethernet Cable
- PC with Windows11 (or Windows10/Ubuntu18.04/ OSX Big Sur)
Software Requirement
- docker
- docker-compose
- Video Software (Display RTSP streams, like VLC/QuickTime/PotPlayer)
- Step 1. Download MaskCam container from Docker Hub.
$sudo docker pull maskcam/maskcam-beta
Note: The docker has already been installed in the reComputer.
- Step 2. Find reComputer IP Address with the command:
$sudo ifconfig
- Step 3. Start MaskCam with docker.
Since we have connected reComputer with a USB camera, we can tab the command below into the terminal to start it. The reComputer IP address we collected above will be filled in <your-jetson-ip>
$sudo docker run --runtime nvidia --privileged --rm -it --env MASKCAM_DEVICE_ADDRESS=<your-jetson-ip> -p 1883:1883 -p 8080:8080 -p 8554:8554 maskcam/maskcam-beta
Note: Replace <your-jetson-ip>
with our IP address in this command.
If you don't want to use the default input device, there are also two different commands to choose and replace the command above.
Use the /dev/video1 camera device:
$sudo docker run --runtime nvidia --privileged --rm -it --env MASKCAM_INPUT=v4l2:///dev/video1 --env MASKCAM_DEVICE_ADDRESS=<your-jetson-ip> -p 1883:1883 -p 8080:8080 -p 8554:8554 maskcam/maskcam-beta
Use the CSI camera device:
$sudo docker run --runtime nvidia --privileged --rm -it --env MASKCAM_INPUT=v4l2://0 --env MASKCAM_DEVICE_ADDRESS=<your-jetson-ip> -p 1883:1883 -p 8080:8080 -p 8554:8554 maskcam/maskcam-beta
- Step 4. View the live video stream through the
MASKCAM_DEVICE_ADDRESS
and then go to the address.
$ MASKCAM_DEVICE_ADDRESS
Streaming at rtsp://aaa.bbb.ccc.ddd:8554/maskcam
Note:aaa.bbb.ccc.ddd
is the address that the information provided by the command MASKCAM_DEVICE_ADDRESS
.
- Step 5. You can copy-paste that URL into your RSTP streaming viewer on other PC or terminal. In the video stream, if you are not wearing a mask, you will see a red frame on your face. Otherwise, you will see a green frame.
In addition to the basic function, we can receive statistics from the device, store them in a database, and have a web-based GUI frontend to display them with the remote server.
In this project, all demos about the server are based on Window11 system host, you can use other Windows versions, or you can find the instruction using Linux system through the MaskCam repository.
- Step1. Install Docker and Docker-compose on your PC
- Step2. Set up build directory
1. Run "Windows PowerShell" as administrator.
2. In the "Windows PowerShell" we can use command line like we use in the reComputer. First, we choose the root of the drive which will be using, such as :
cd e:\
3. Download MaskCam repo:
Invoke-WebRequest https://github.com/bdtinc/maskcam/archive/refs/heads/main.zip -OutFile e:\maskcam.zip
4. Here we unzip it to the path e:\maskcam
:
Expand-Archive e:\maskcam.zip -DestinationPath e:\maskcam
5. Move To the MaskCam server folder where it contains four containers:
- Mosquitto broker
- Backend API
- Database
- Streamlit frontend
cd maskcam\maskcam-main\server
6. Then, create the .env
files by copying the default templates:
cp database.env.template database.env
cp frontend.env.template frontend.env
cp backend.env.template backend.env
7. Open the database.env
:
notepad database.env
In the file, replace the <DATABASE_USER>
, <DATABASE_PASSWORD>
, and <DATABASE_NAME>
fields with our own PC information.
- Step3. Build and run local server
1. After editing the database environment file, we are ready to build all the containers and run them with a single command:
sudo docker-compose up -d
The docker will be shown as:
2. Next, open a web browser and enter the server IP to visit the frontend webpage:
http://<server IP>:8501/
Note: The <server IP>
is our own PC IP address.
Hint: If you see a ConnectionError
in the frontend, wait a couple more seconds and reload the page. Because sometimes the backend container can take some time to finish the database setup. If the ConnectionError
still exists, in the frontend, please make sure the ports: <5432> and <80> are not being occupied or listened up.
If you visit the frontend webpage successfully the first time but failed the next, the best way to solve it currently is to re-install docker.
- Step4. Set reComputer as your local server
Return to reComputer's terminal, and then run the MaskCam container with the command below:
sudo docker run --runtime nvidia --privileged --rm -it --env MQTT_BROKER_IP=<server IP> --env MQTT_DEVICE_NAME=my-jetson-1 --env MASKCAM_DEVICE_ADDRESS=<your-jetson-ip> -p 1883:1883 -p 8080:8080 -p 8554:8554 maskcam/maskcam-beta
Note: Replace <server IP>
and <your-jetson-ip>
with our own server and the IP address of reComputer that we collected before.
After that, we can choose the devices on webpage as shown below:
- Step5. Finally, we can see the data collected by reComputer transmitting to the Server.
Comments