<p>There is <a href="https://remove.bg" rel="nofollow noreferrer">remove.bg</a><br>
It is the most easy tool,to remove background automatically <br>
Sample code:-https://www.remove.bg/api#sample-code<br>
Screenshots:
<a href="https://i.stack.imgur.com/VINyB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VINyB.png" alt="Picture" /></a>
<a href="https://i.stack.imgur.com/ChX7P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ChX7P.png" alt="picture2" /></a>
Here is an example of doing in Python:</p>
<pre><code># Requires &quot;requests&quot; 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(&quot;Error:&quot;, response.status_code, response.text)
</code></pre>
<p>Since your are using <code>python</code> ,
This <a href="https://github.com/brilam/remove-bg" rel="nofollow noreferrer">https://github.com/brilam/remove-bg</a> by @brilam will help you.<br>
It is a Python API wrapper for removing backgrounds from picture using remove.bg's API.
But it also offers <code>go</code> based command line tool:-https://github.com/remove-bg/go</p>
<hr />
<blockquote>
<p>In addition to that, there are many other opensource library for python in GitHub for your reference: <br> <a href="https://github.com/topics/background-removal?l=python" rel="nofollow noreferrer">https://github.com/topics/background-removal?l=python</a><br></p>
</blockquote>
<blockquote>
<p>Also, you can try, <br>
<a href="https://github.com/danielgatis/rembg" rel="nofollow noreferrer">https://github.com/danielgatis/rembg</a></p>
</blockquote>
<blockquote>
<p>OR, refer research paper for your understanding: <a href="https://arxiv.org/pdf/2005.09007.pdf" rel="nofollow noreferrer">https://arxiv.org/pdf/2005.09007.pdf</a></p>
</blockquote>
Pixellib - removing background takes huge processing
<p>I am using Pixellib library in Python to detect a person and change its background, as shown in their example <a href="https://pixellib.readthedocs.io/en/latest/change_image_bg.html" rel="nofollow noreferrer">here</a>.</p>
<p>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.</p>
<p>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.</p>
<p>So, how do achieve this? Apps like <a href="https://www.canva.com/pro/background-remover/" rel="nofollow noreferrer">Canva Pro</a> seem to do this seamlessly in an app <a href="https://static-cse.canva.com/video/753559/02_CANVA_ProFeatures_BackgroundRemover.mp4" rel="nofollow noreferrer">fairly quickly</a>. In fact, there are many other 'free' apps on Play store claiming to do the same.</p>
<p>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?</p>