Real-Time Face & Object Detection Using OpenCV and MediaPipe
Hey folks! 👋
Real-Time Face & Object Detection Using OpenCV and MediaPipe

Hey folks! 👋
I hope you guys have been doing great lately and learning something new every day.
So, coming back with another interesting Computer Vision project. In my previous projects, we worked with some of the traditional approaches in OpenCV, and this time I wanted to try something a little different.
What if we could detect faces and objects directly from a live webcam — in real time — using a lightweight model?
Sounds interesting, right? 👀
That’s exactly what we are going to build in this blog using OpenCV and MediaPipe.
The interesting part here is that we don’t need some huge deep learning model that takes hundreds of megabytes just to detect something in front of our camera.

Instead, we can use a small and lightweight MediaPipe model of roughly 8 MB and run detection directly on our live webcam feed.
And honestly, this is one of the things I really like about modern Computer Vision — you don’t always need a massive model to build something useful.
Sometimes a small, optimized model + a good pipeline is enough to create something that works surprisingly well. 🚀
What Are We Building?
Before jumping into the code, let’s understand what we are actually trying to achieve.
Our application will continuously take frames from the webcam and pass them through the MediaPipe detection pipeline.
The basic flow will look something like this:

And because this happens continuously for every frame, we get a real-time detection system.
The cool thing is that once the webcam starts, you can move around in front of it and the model will continuously try to identify what it sees.
Why MediaPipe?
Now you might be wondering:
“Why MediaPipe? We already have OpenCV.”
Well, OpenCV is excellent for image and video processing, but MediaPipe gives us access to pre-built machine-learning solutions and optimized models for tasks such as face detection, face landmarks, hand tracking, pose estimation, and object detection.
This means we don’t have to start by training our own model from scratch.
We can simply load a suitable pre-trained model and use it with our OpenCV webcam pipeline.
And that’s what makes this project interesting for beginners.
We get to see how Computer Vision + Machine Learning + real-time video processing can work together without building everything from zero.
The Model Is Surprisingly Small
One thing that caught my attention while working on this project was the model size.
We are working with a model that’s only around 8 MB.
When you compare that with many modern deep-learning models, that’s quite lightweight.
And this matters because smaller models can be much more practical when you want to run Computer Vision applications on systems with limited computational resources.
For a beginner project, this also makes things much easier to experiment with.
You don’t need a massive GPU setup just to understand the basic pipeline.
Understanding the Overall Pipeline
Let’s break the complete process into simple steps.
1. Capture the Webcam Frame
First, OpenCV connects to our webcam and continuously captures frames.
cap = cv.VideoCapture(0)
Every frame is basically an image.
So if our camera is running at around 30 FPS, we are essentially receiving around 30 images every second.
2. Send the Frame to the Model
Once we have a frame, we pass it to the MediaPipe model.
The model looks at the image and tries to identify the objects or faces it was trained to detect.
This is where the machine-learning part comes into the picture.
We don’t manually tell the program:
“There is a face between these coordinates.”
Instead, the model analyzes the image and gives us the detected regions.
3. Get the Detection Results
The model returns information about what it detected.
Depending on the model being used, this can include things such as:
- The detected object
- Confidence score
- Bounding box
- Location of the detected object
For example, the model might return something conceptually like:
Object: Person
Confidence: 0.92
Bounding Box: x, y, width, height
Now we have enough information to draw the detection on our original webcam frame.
4. Draw the Bounding Box
Once we know where the object is, OpenCV can draw a rectangle around it.
cv.rectangle(frame, ...)
This gives us the familiar computer-vision output:
“Hey! I found something here.”
We can also display the class name and confidence score above the bounding box.
5. Display the Result
Finally, OpenCV displays the processed frame:
cv.imshow("Detection", frame)
And because everything happens inside a loop, the process keeps repeating:
Capture → Detect → Draw → Display → Capture again
This is what gives us the real-time effect.
OpenCV + MediaPipe
One thing I want you to notice here is that we aren’t really replacing OpenCV with MediaPipe.
Instead, we are using them together.
Think of it this way:
OpenCV handles the video.
MediaPipe handles the machine-learning detection.
And together they give us a complete real-time Computer Vision application.
This combination is actually quite powerful for small projects and experiments.
What I Learned From This Project
For me, the interesting part of this project wasn’t just getting a bounding box around an object.
It was understanding how the different pieces fit together.
We started with a simple webcam feed.
Then we introduced a lightweight ML model.
Then we used that model to understand the contents of each frame.
And finally, we used OpenCV to visualize the model’s predictions.
So the complete idea becomes:
Camera → Image → ML Model → Prediction → Visualization
And this basic pipeline is behind many real-world Computer Vision applications.
Of course, production-level systems can become much more complicated, but understanding this basic flow gives you a solid starting point.
Final Thoughts
I hope this project gave you a simple introduction to how we can combine OpenCV and MediaPipe to build real-time Computer Vision applications.
What I really like about projects like this is that they make Computer Vision feel much less intimidating.
You don’t always need to start with complicated architectures, huge datasets, or hundreds of lines of code.
Sometimes, start small.
Take a webcam.
Take a lightweight model.
Understand how the frames move through the pipeline.
Then slowly build on top of it.
That’s how we learn. 🚀
And if you enjoyed this project, don’t stop here. Try changing the model, experiment with different detection thresholds, add FPS counters, detect multiple objects, or even combine detection with other OpenCV operations.
There is always something new to experiment with.
Keep learning. Keep building. Keep experimenting.
Happy Learning! ❤️
메타데이터
- post_id
- 6ca4eca40484
- slug
- real-time-face-object-detection-using-opencv-and-mediapipe-6ca4eca40484
- url
- https://medium.com/@mayankgariya482/real-time-face-object-detection-using-opencv-and-mediapipe-6ca4eca40484
- canonical_url
- https://medium.com/@mayankgariya482/real-time-face-object-detection-using-opencv-and-mediapipe-6ca4eca40484
- author_url
- https://medium.com/@mayankgariya482
- status
- ok
- fetched_at
- 2026-08-12 23:48:45