Selfie segmentation using OpenCV?

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 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

impossible.

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

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

crosspost:

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

//
// 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;
}
1 Like