# Selfie segmentation using OpenCV?

**URL:** <https://forum.opencv.org/t/selfie-segmentation-using-opencv/14699>\
**Category:** Uncategorized\
**Created:** [September 29, 2023, 5:51pm UTC](https://forum.opencv.org/t/selfie-segmentation-using-opencv/14699 "2023-09-29T17:51:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![t.jasmin111](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/t.jasmin111/32/8327_2.png) [@t.jasmin111](https://forum.opencv.org/u/t.jasmin111)\
**Post date:** [September 29, 2023, 5:51pm UTC](https://forum.opencv.org/t/selfie-segmentation-using-opencv/14699/1 "2023-09-29T17:51:02Z")

</div>

I want to perform selfie segmentation on Android, similar to what Zoom does. However, I would like to do it preferrably without using deep learning models and instead rely solely on conventional image processing and computer vision techniques, such as using only OpenCV or just Android SDK. Google [MLKit](https://developers.google.com/ml-kit/vision/selfie-segmentation) or Mediapipe have this functionalities but I don’t want to include a large library to do so. My goal is to achieve fast selfie segmentation; may not be very accurate but it’s fine.

How can I do that? I assume apps like Zoom were probably using image processing techniques before using deep learning models, so there should be ways to achieve that.

[![enter image description here](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/1/18be73b8e71d65a8f8449a9e54f1c008205a9902.jpeg)](https://i.stack.imgur.com/nqgefm.png)

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [September 29, 2023, 8:07pm UTC](https://forum.opencv.org/t/selfie-segmentation-using-opencv/14699/2 "2023-09-29T20:07:11Z")

</div>

> [@t.jasmin111](#):
>
> without using deep learning models

impossible.

> [@t.jasmin111](#):
>
> apps like Zoom were probably using image processing techniques before using deep learning models

no they weren’t. because that doesn’t work.

you aren’t gonna require users to stand in front of a greenscreen, right?

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [September 30, 2023, 9:35am UTC](https://forum.opencv.org/t/selfie-segmentation-using-opencv/14699/3 "2023-09-30T09:35:17Z")

</div>

[crosspost](https://meta.stackoverflow.com/a/266159):

> <https://stackoverflow.com/questions/77203768/selfie-segmentation-using-image-processing-techniques>

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [September 30, 2023, 9:35am UTC](https://forum.opencv.org/t/selfie-segmentation-using-opencv/14699/4 "2023-09-30T09:35:20Z")

</div>



---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [October 1, 2023, 6:23am UTC](https://forum.opencv.org/t/selfie-segmentation-using-opencv/14699/5 "2023-10-01T06:23:52Z")

</div>

you can do this using opencv alone, however this task needs a dnn, forget ‘conventional image processing’

```auto
//
// https://github.com/PINTO0309/PINTO_model_zoo/tree/main/109_Selfie_Segmentation
//
#include <iostream>

#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/dnn.hpp>
#include <opencv2/core.hpp>

int main()
{
    cv::Size inputSizeNewBarracuda = cv::Size(256, 256);

    std::string imagefilename = "img/pers.png";
    std::string newBarracuda = "C:/data/dnn/selfie/model_float32.pb";

    cv::dnn::Net net = cv::dnn::readNet(newBarracuda);

    cv::Mat img = cv::imread(imagefilename);
    cv::Mat blob = cv::dnn::blobFromImage(img, 1.0/255, inputSizeNewBarracuda, cv::Scalar(), false, false, CV_32F);
    net.setInput(blob);

    cv::Mat output = net.forward();
    cv::Mat mask = output.reshape(1,256) > 0.5;
	cv::imshow("I",mask);
	cv::waitKey();

	return 0;
}

```
