RashCam is mainly a smart dash-cam equipped with state-of-the-art yet cheap and easily available sensors. This device can detect bad driving behaviors like speeding, aggressive driving & hard cornering. And notify the vehicle owner regarding these events along with video clip from the dashboard of the vehicle.

Sep 2021 - Jun 2022

RashCam
RashCam

Overview

RashCam was our final year project for Bachelor’s degree in Computer Science at COMSATS University Islamabad.

This project consists of three main components:

  1. RashCam Device (IoT Hardware)
    • Raspberry PI 4
    • Raspberry PI Camera
    • IMU Sensor (9DOF)
    • GPS Sensor
  2. Device Software
    • Python
    • Linux
    • GStreamer
    • WebRTC
    • Mender (OTA Updates)
  3. Web Application
    • Client App (Next.js)
    • Backend Server (Django)
    • Signaling Server
    • TURN Server (coturn)
    • PostgreSQL Database
    • Redis Cache/Queue
    • Celery Workers

Rashcam Device

Rashcam Hardware
Rashcam Hardware

For some reason our Magnetic sensor from IMU was not working properly, so we had to use a compass module instead.


Device Software

The software stack of the device is divided into two parts:

  1. Firmware - The operating system and drivers for the device and all the supporting libraries.
  2. Application - The main python application which runs on top of the firmware.

Firmware:

OS: We used Raspberry PI OS as our base operating system. It is a Debian based Linux distribution. We tried to use fedora IoT, but it was not stable enough for our use case.

Video Streaming: We used GStreamer to stream video from the camera. GStreamer is a pipeline based multimedia framework. It is used to create complex multimedia pipelines for video streaming, video recording, video encoding, video decoding, video transcoding, etc.

OTA Updates: We used Mender to manage OTA updates for our device. Mender is an open source OTA update manager for embedded Linux devices. Which helped us to update our device software remotely.

Application:

We picked Python as the main language for our app because it’s easy to use and flexible. This was super helpful, especially when dealing with a tricky and unclear problem. It let us quickly try out and change our ideas as we worked on the project. GStreamer Python Bindings helped us in creating GStreamer pipelines in python.

The nature of the application leads us to implement a complete event driven architecture to handle all the events from different sensors and video streams and process them accordingly.

Video SourceVideo EncoderSplit ChunkRecorderWebRtc Bin (n)IMU SourceRoling FiltersDistinct FilterThrottle FilterCompassClassifierRest API SinkWebSocketSinkGPS Source
Rashcam streams flow

The above diagram shows the flow of events from different sources to different sinks. Before we dive into the details of each component, let’s first define some terms:

Now with these definitions in mind here is the architecture:

This is the whole architecture of our RashCam device but, I would like to mention one more piece of the puzzle, when the Classifier signals the Split Chunk Recorder, we need the 30-second video to be uploaded to the server. We archive this by following algo:

  1. Copy previous 10 seconds chunk, wait for current and a future chunk to completed and copy them too.
  2. If there isn’t another event for next 3 chunks (30s), merge 3 copied chunks into one video and upload it to the server.
  3. Else repeat the step one until we have no event for next 30s.

It seems very simple in words but believe me that was one of the hardest thing we solved in this whole project.


Web Application

The purpose of the application is to provide a dashboard for the user to view the live stream from the device, view the detected incidents and view the recorded videos. The web app also provides a way to configure the device and view the device status.

RashCam device uses TURN server for WebRTC communication, websocket for signaling and RestAPI for posting data like detected incidents/video chunks to server.

PostgreSQL DatabaseRedis Cache/QueueCelery WorkersClient AppRashCamTURN ServerSignaling ServerWeb ServerBackend Server
Rashcam Software Architecture

The backend server is responsible for providing the REST APIs for the web app and the device. It also provides the signaling server and the TURN server for the WebRTC connections.

The backend was build using a number of technologies:

On frontend side, we have NextJS that serves the web app. Our web app is quite simple with 3 to 4 routes other than the authentication pages. Web app communicates with backend via REST APIs.

Conclusion

The nature of this project was very different from the kind of projects we were conformable developing but, again this was one of the reasons we choose this project. We wanted to learn new things and we did. We faced a lot of issues during the development of this project. Some of them were easy to solve and some of them were really hard. But, we managed to solve them all.

We learned a lot of new things during the development of this project:

We are really thankful to our supervisor Dr. Usama Ijaz Bajwa for his guidance and support throughout the project.

About Team