Chapter 14: Implement a Real-Time Face Detection System Using WebSockets with FastAPI and OpenCV
In the previous chapter, you learned how to create efficient REST API endpoints to make predictions with trained machine learning models. This approach covers a lot of use cases, given that we have a single observation we want to work on. In some cases, however, we may need to continuously perform predictions on a stream of input, for instance, a face detection system that works in real time with video input. This is exactly what we'll build in this chapter. How? If you remember, besides HTTP endpoints, FastAPI also has the ability to handle WebSockets endpoints, which allow us to send and receive streams of data. In this case, the browser will send into the WebSocket a stream of images from the webcam, and our application will run a face detection algorithm and send back the coordinates of the detected face in the image. For this face detection task, we'll rely on OpenCV, which...