HMS-Core / hms-ml-demo

HMS ML Demo provides an example of integrating Huawei ML Kit service into applications. This example demonstrates how to integrate services provided by ML Kit, such as face detection, text recognition, image segmentation, asr, and tts.
https://developer.huawei.com/consumer/en/hms/huawei-mlkit?ha_source=hms1
Apache License 2.0
356 stars 120 forks source link

Removing the background from a video takes a long time to finish #79

Open Ali-cryptoo opened 3 years ago

Ali-cryptoo commented 3 years ago

Hi, I hope you're doing well, I'm trying to remove the background from a video, right now I'm following those steps :

1 - Extract all frames from video using FFMPEG

2 - Remove the background from each frame using Huawei ML Image Segmentation and save the bitmap as file to use it later :

    public void analyzer(List<File> files, MLCallBack mlCallBack) {
        for (File file : files) {
            Bitmap frame = ImageUtils.getBitmap(file);
            MLFrame mlFrame = MLFrame.fromBitmap(frame);
            SparseArray<MLImageSegmentation> task = this.analyzer.analyseFrame(mlFrame);
            String noBgFramePath = FileHelper.createImageInNoBackgroundFramesFolder(counter);
            ImageUtils.save(task.get(0).getForeground(), noBgFramePath, Bitmap.CompressFormat.PNG, 60, true);
            mlCallBack.onMLProgress(counter);
            BitmapUtil.recycle(frame);
            FileUtils.delete(file);
            counter++;
        }
        if (counter == files.size())
            mlCallBack.onMLCompleted(true);
    }

3 - Combine all frames (no background) into one video file.

THE ISSUE :

The step 2 (Removing background) takes a long time e.g. video with 26sec takes almost 5min to process, is there any better and faster way to do this, such as using LensEngine or something like that?