4

I am using Pixellib library in Python to detect a person and change its background, as shown in their example here.

It works flawlessly, but takes huge processing power on my laptop, coupled with their large (~150mb) pascalvoc model, thus rendering an image in approx 4-5sec.

I need to be able to do the same via a mobile phone app, so certainly this cannot be run on a user's mobile. Alternative is to run this on cloud and return the processed image back. This is both costly if user requests increase and will still have noticable lag on user's app.

So, how do achieve this? Apps like Canva Pro seem to do this seamlessly in an app fairly quickly. In fact, there are many other 'free' apps on Play store claiming to do the same.

Thus, is there a better way to run Pixellib, to make it more performant? Or any other library that can provide similar (or better) ouptut and can be run on user's mobile?

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
sppc42
  • 2,994
  • 2
  • 31
  • 49
  • Maybe you could give OpenCV's [GrabCut](https://docs.opencv.org/4.5.5/d8/d83/tutorial_py_grabcut.html) algorithm a try. [Here's](https://stackoverflow.com/a/67478981/12728244) an example of the algorithm in action. Another tip for speeding up the process involves downscaling the image, get a foreground mask, upscale the mask and apply it to the original image. – stateMachine Jan 02 '22 at 01:51

1 Answers1

-3

There is remove.bg
It is the most easy tool,to remove background automatically
Sample code:-https://www.remove.bg/api#sample-code
Screenshots: Picture picture2 Here is an example of doing in Python:

# Requires "requests" to be installed (see python-requests.org)
import requests

response = requests.post(
'https://api.remove.bg/v1.0/removebg',
files={'image_file': open('/path/to/file.jpg', 'rb')},
data={'size': 'auto'},
headers={'X-Api-Key': 'INSERT_YOUR_API_KEY_HERE'},
)
if response.status_code == requests.codes.ok:
    with open('no-bg.png', 'wb') as out:
        out.write(response.content)
else:
    print("Error:", response.status_code, response.text)

Since your are using python , This https://github.com/brilam/remove-bg by @brilam will help you.
It is a Python API wrapper for removing backgrounds from picture using remove.bg's API. But it also offers go based command line tool:-https://github.com/remove-bg/go


In addition to that, there are many other opensource library for python in GitHub for your reference:
https://github.com/topics/background-removal?l=python

Also, you can try,
https://github.com/danielgatis/rembg

OR, refer research paper for your understanding: https://arxiv.org/pdf/2005.09007.pdf

Neptotech -vishnu
  • 1,096
  • 8
  • 23
  • 3
    The terms of use for Remove.bg say "The Operator has the right to restrict the use of the Platform without giving reasons or to block Users.". I wouldn't count on it for any critical uses :) – AKX Jan 01 '22 at 10:09
  • @ hifi tech The answer would be better, if you suggest what is in that link -- short summary or screenshot. The current answer is not more useful. – susan097 Jan 03 '22 at 02:09
  • added some pictures – Neptotech -vishnu Jan 03 '22 at 05:28
  • 1
    This is not a solution to the problem OP has brought forward. He asks "is there a better way to run Pixellib, to make it more performant? Or any other library that can provide similar (or better) output?" – Mo. Atairu Jan 06 '22 at 10:47
  • yes this library gives better output – Neptotech -vishnu Jan 06 '22 at 12:13