Package: transparent-background-dev
Transparent BackgroundThis is a background removing tool powered byInSPyReNet (ACCV 2022). You can easily remove background from the image or video or bunch of other stuffs when you can make the background transparent!ImageVideoWebcam:inbox_tray: InstallationDependencies (python packages)packageversion (>=)pytorch1.7.1torchvision0.8.2opencv-python4.6.0.66timm0.6.11tqdm4.64.1kornia0.5.4gdown4.5.4pyvirtualcam0.6.0Note: If you have any problem withpyvirtualcam, please visit their github repository or pypi homepage. Due to the backend workflow for Windows and macOS, we only support Linux for webcam input.Dependencies (webcam input)We basically follow the virtual camera settings frompyvirtualcam. If you do not choose to install virtual camera, it will visualize real-time output withcv2.imshow.A. Linux (v4l2loopback)# Install v4l2loopback for webcam relay$gitclonehttps://github.com/umlaeute/v4l2loopback.git&&cdv4l2loopback
$make&&sudomakeinstall
$sudodepmod-a# Create virtual webcam$sudomodprobev4l2loopbackdevices=1Note: If you have any problem with installingv4l2loopback, please visit their github repository.B. Windows (OBS)Install OBS virtual camera frominstall OBS.C. macOS (OBS) [not stable]Follow the steps below.Install OBS.Start OBS.Click "Start Virtual Camera" (bottom right), then "Stop Virtual Camera".Close OBS.Installtransperent-background# via pypi$pipinstalltransparent-background# via github$pipinstallgit+https://github.com/plemeri/transparent-background.git# locally$pipinstall-e.:pencil2: Usage:computer: Command Line$transparent-background--source[SOURCE]--dest[DEST]--type[TYPE]--fast# for apple silicon mps backend (requires torch >= 1.13)$PYTORCH_ENABLE_MPS_FALLBACK=1transparent-background--source[SOURCE]--dest[DEST]--type[TYPE]--fast--source [SOURCE]: Specify your data in this argument.Single image -image.pngFolder containing images -path/to/img/folderSingle video -video.mp4Folder containing videos -path/to/vid/folderInteger for webcam address -0(e.g., if your webcam is at/dev/video0.)--dest [DEST](optional): Specify your destination folder. If not specified, it will be saved in current directory.--type [TYPE]: Choose betweenrgba,mapgreen,blur,overlay, and another image file.rgbawill generate RGBA output regarding saliency score as an alpha map. Note that this will not work for video and webcam input.mapwill output saliency map only.greenwill change the background with green screen.blurwill blur the background.overlaywill cover the salient object with translucent green color, and highlight the edges.Another image file (e.g.,backgroud.png) will be used as a background, and the object will be overlapped on it.--fast: Fast mode. If specified, it will use low-resolution input and model trained with LR scale. May decrease performance but reduces inference time and gpu memory usage.Examples of different TYPE argument choices:crystal_ball: Python APIUsage Exampleimportcv2fromPILimportImagefromtransparent_backgroundimportRemoverremover=Remover()# Usage for imageimg=Image.open('samples/aeroplane.jpg')# read imageout=remover.process(img)# default setting - transparent backgroundout=remover.process(img,type='rgba')# same as aboveout=remover.process(img,type='map')# object map onlyout=remover.process(img,type='green')# image matting - green screenout=remover.process(img,type='blur')# blur backgroundout=remover.process(img,type='overlay')# overlay object map onto the imageout=remover.process(img,type='samples/background.jpg')# use another image as a backgroundImage.fromarray(out).save('output.png')# save result# Usage for videocap=cv2.VideoCapture('samples/b5.mp4')# video reader for inputfps=cap.get(cv2.CAP_PROP_FPS)writer=Nonewhilecap.isOpened():ret,frame=cap.read()# read videoifretisFalse:breakframe=cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)img=Image.fromarray(frame).convert('RGB')ifwriterisNone:writer=cv2.VideoWriter('output.mp4',cv2.VideoWriter_fourcc(*'mp4v'),fps,img.size)# video writer for outputout=remover.process(img,type='map')# same as image, except for 'rgba' which is not for video.writer.write(cv2.cvtColor(out,cv2.COLOR_BGR2RGB))cap.release()writer.release():outbox_tray: Uninstallpip uninstall transparent-background:page_facing_up: LicenceSeeLICENCEfor more details.