---
title: Raspberry Pi Video Live Streaming with AI - Part 2 – WebRTC.ventures
description: "Last month, we streamed video from a Raspberry Pi, applied a filter to it on the server, and streamed it live to dozens of users. In the second part of this project, we'll go a little deeper and do something more complex with OpenCV: implement face detection on the server."
---

[WebRTC.ventures Blog](https://blog.webrtc.ventures)

# [Raspberry Pi Video Live Streaming with AI - Part 2 – WebRTC.ventures](https://blog.webrtc.ventures/2019/09/raspberry-pi-video-live-streaming-with-ai-part-2)

 Written by [Alberto Gonzalez](https://blog.webrtc.ventures/author/alberto-gonzalez) | Sep 24, 2019 4:00:00 AM

[Last month](https://webrtc.ventures/2019/08/raspberry-pi-video-live-streaming-with-ai/), we streamed video from a Raspberry Pi, applied a filter to it on the server, and streamed it live to dozens of users. In the second part of this project, we’ll go a little deeper and do something more complex with OpenCV: implement face detection on the server.

If you want to jump directly to the code, you can find the demo project [here](https://github.com/agonza1/WebRTC-Live-Streaming-with-AI). If you install the modules and then run *node videoFaceDetection* in /video-ai-service, you should see a demo video with applied face detection.

## Face detection

For face detection, we can use the demo code in opencv4node [here](https://github.com/justadudewhohacks/opencv4nodejs/tree/master/examples). We just need to make some modifications to reduce latency and send and receive UDP packets.

Below we have videoFaceDetection.js, where we declare the [CascadeClassifier](https://docs.opencv.org/3.4/db/d28/tutorial_cascade_classifier.html) and other main variables and functions that happen in “runVideoFaceDetection()”:

In runVideoFaceDetection, the video stream will apply the CascadeClassifier and add a square around each detected face. After that, the modified UDP stream is sent to Janus and delivered to web clients using WebRTC.

To test it out with a prerecorded video, you can change videoIn to:

Then you’ll be able to run *node videoFaceDetection* and see something like this in your local machine:

If it works with the demo video, change it back to use the UDP incoming stream from the Raspberry Pi.

If you’re still having problems and can’t see the stream in the web client, you can [try](https://github.com/agonza1/WebRTC-Live-Streaming-with-AI/blob/master/video-ai-service/index.js)*[node index.js](https://github.com/agonza1/WebRTC-Live-Streaming-with-AI/blob/master/video-ai-service/index.js)* to generate a test source media stream and verify that the media stream is being received by Janus.

## What do we build next?

As you can see, once you have a running ML live streaming solution, implementing other image detection operations for a specific use case can be achieved easily. There are many interesting examples that we’ll play around in the future, like hand gesture recognition, object detection, and even pose detection.

[**Contact us**](https://webrtc.ventures/contact/) to build the next generation of video applications!

[View full post](https://blog.webrtc.ventures/2019/09/raspberry-pi-video-live-streaming-with-ai-part-2)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Alberto Gonzalez"
  },
  "dateModified" : "2024-04-03T19:03:05.172Z",
  "datePublished" : "2019-09-24T04:00:00Z",
  "headline" : "Raspberry Pi Video Live Streaming with AI - Part 2",
  "image" : {
    "@type" : "ImageObject",
    "height" : 512,
    "url" : "https://45353883.fs1.hubspotusercontent-na1.net/hubfs/45353883/Imported_Blog_Media/Copy-of-Raspberry-Pi-Video-Live-Streaming-with-AI.png",
    "width" : 1024
  },
  "mainEntityOfPage" : "https://blog.webrtc.ventures/2019/09/raspberry-pi-video-live-streaming-with-ai-part-2",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60,
      "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
      "width" : 60
    },
    "name" : "WebRTC.ventures Blog"
  }
}
```