I am trying to run a simple task in python. rembg (remove background)
the task doesnt run .. I get syntax errors. I am not sure about the syntax for the paths that I am using.
I also dont know how this pil or pillow thing works.
the original looks like this:
Code: Select all
from rembg import remove
from PIL import Image
input_path = 'input.jpg' # input image path
output_path = 'output.png' # output image path
input = Image.open(input_path) # load image
output = remove(input) # remove background
output.save(output_path) # save image
Code: Select all
from rembg import remove
from PIL import Image
input_path = '/home/rocket/Pictures/Morts.png' # input image path
output_path = '/home/rocket/Pictures/' # output image path
input = Image.open(/home/rocket/Pictures/Morts.png) # load image
output = remove(/home/rocket/Pictures/Morts.png) # remove background
output.save(/home/rocket/Pictures/mortsbg.png) # save image
Code: Select all
rocket@rocket-Latitude-E6520:~$ python
Python 3.8.10 (default, Nov 22 2023, 10:22:35)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from rembg import remove
>>> from PIL import Image
>>>
>>>
>>> input_path = '/home/rocket/Pictures/Morts.png' # input image path
>>> output_path = '/home/rocket/Pictures/' # output image path
>>>
>>> input = Image.open(/home/rocket/Pictures/Morts.png) # load image
File "<stdin>", line 1
input = Image.open(/home/rocket/Pictures/Morts.png) # load image
^
SyntaxError: invalid syntax
>>> output = remove(/home/rocket/Pictures/Morts.png) # remove background
File "<stdin>", line 1
output = remove(/home/rocket/Pictures/Morts.png) # remove background
^
SyntaxError: invalid syntax
>>> output.save(/home/rocket/Pictures/mortsbg.png) # save image
File "<stdin>", line 1
output.save(/home/rocket/Pictures/mortsbg.png) # save image
^
SyntaxError: invalid syntax
>>>
/home/rocket/Pictures/Morts.png
so as you can see its running in python 3.8 I dont know how pil or pillow works. I have installed pillow.
Are my script lines incorrect .. pls show correct entries.
system report:
Code: Select all
System: Kernel: 5.4.0-171-generic x86_64 bits: 64 compiler: gcc v: 9.4.0
Desktop: Cinnamon 4.6.7 wm: muffin dm: LightDM Distro: Linux Mint 20 Ulyana
base: Ubuntu 20.04 focal
Machine: Type: Laptop System: Dell product: Latitude E6520 v: 01 serial: <filter> Chassis:
type: 9 serial: <filter>
Mobo: Dell model: 0J4TFW v: A01 serial: <filter> BIOS: Dell v: A06 date: 07/11/2011
Battery: ID-1: BAT0 charge: 43.2 Wh condition: 43.2/48.8 Wh (89%) volts: 12.6/11.1
model: SMP DELL P8TC727 serial: <filter> status: Full
CPU: Topology: Dual Core model: Intel Core i5-2540M bits: 64 type: MT MCP arch: Sandy Bridge
rev: 7 L2 cache: 3072 KiB
flags: avx lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx bogomips: 20755
Speed: 3093 MHz min/max: 800/3300 MHz Core speeds (MHz): 1: 3093 2: 3217 3: 3093
4: 3196
Graphics: Device-1: Intel 2nd Generation Core Processor Family Integrated Graphics vendor: Dell
driver: i915 v: kernel bus ID: 00:02.0 chip ID: 8086:0126
Device-2: NVIDIA GF119M [NVS 4200M] vendor: Dell driver: nvidia v: 390.157
bus ID: 01:00.0 chip ID: 10de:1056
Display: x11 server: X.Org 1.20.13 driver: modesetting,nvidia
unloaded: fbdev,nouveau,vesa resolution: 1600x900~60Hz, 1920x1080~60Hz
OpenGL: renderer: NVS 4200M/PCIe/SSE2 v: 4.6.0 NVIDIA 390.157 direct render: Yes
Audio: Device-1: Intel 6 Series/C200 Series Family High Definition Audio vendor: Dell
driver: snd_hda_intel v: kernel bus ID: 00:1b.0 chip ID: 8086:1c20
Device-2: NVIDIA GF119 HDMI Audio vendor: Dell driver: snd_hda_intel v: kernel
bus ID: 01:00.1 chip ID: 10de:0e08
Sound Server: ALSA v: k5.4.0-171-generic
Network: Device-1: Intel 82579LM Gigabit Network vendor: Dell driver: e1000e v: 3.2.6-k
port: 5080 bus ID: 00:19.0 chip ID: 8086:1502
IF: eno1 state: down mac: <filter>
Device-2: Intel Centrino Ultimate-N 6300 driver: iwlwifi v: kernel port: 4000
bus ID: 03:00.0 chip ID: 8086:422b
IF: wlp3s0 state: up mac: <filter>
Drives: Local Storage: total: 465.76 GiB used: 46.01 GiB (9.9%)
ID-1: /dev/sda vendor: Toshiba model: MK5061GSYN size: 465.76 GiB speed: 3.0 Gb/s
serial: <filter>
RAID: Hardware-1: Intel 82801 Mobile SATA Controller [RAID mode] driver: ahci v: 3.0
bus ID: 00:1f.2 chip ID: 8086.282a
Partition: ID-1: / size: 76.35 GiB used: 46.01 GiB (60.3%) fs: ext4 dev: /dev/sda5
USB: Hub: 1-0:1 info: Full speed (or root) Hub ports: 3 rev: 2.0 chip ID: 1d6b:0002
Hub: 1-1:2 info: Intel Integrated Rate Matching Hub ports: 6 rev: 2.0
chip ID: 8087:0024
Device-1: 1-1.4:3 info: Dell DW375 Bluetooth Module type: Bluetooth driver: btusb
rev: 2.0 chip ID: 413c:8187
Hub: 2-0:1 info: Full speed (or root) Hub ports: 3 rev: 2.0 chip ID: 1d6b:0002
Hub: 2-1:2 info: Intel Integrated Rate Matching Hub ports: 8 rev: 2.0
chip ID: 8087:0024
Device-2: 2-1.4:3 info: Logitech M105 Optical Mouse type: Mouse
driver: hid-generic,usbhid rev: 2.0 chip ID: 046d:c077
Device-3: 2-1.8:4
info: Broadcom BCM5880 Secure Applications Processor with fingerprint swipe sensor
type: Smart Card driver: N/A rev: 1.1 chip ID: 0a5c:5801
Sensors: System Temperatures: cpu: 67.0 C mobo: 31.0 C sodimm: 41.0 C gpu: nvidia temp: 60 C
Fan Speeds (RPM): cpu: 2676
Repos: No active apt repos in: /etc/apt/sources.list
Active apt repos in: /etc/apt/sources.list.d/brave-browser-release.list
1: deb [signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg] https: //brave-browser-apt-release.s3.brave.com/ stable main
Active apt repos in: /etc/apt/sources.list.d/official-package-repositories.list
1: deb http: //packages.linuxmint.com ulyana main upstream import backport #id:linuxmint_main
2: deb http: //archive.ubuntu.com/ubuntu focal main restricted universe multiverse
3: deb http: //archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse
4: deb http: //archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
5: deb http: //security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
6: deb http: //archive.canonical.com/ubuntu/ focal partner
Active apt repos in: /etc/apt/sources.list.d/opera-stable.list
1: deb https: //deb.opera.com/opera-stable/ stable non-free #Opera Browser (final releases)
Info: Processes: 245 Uptime: 3h 20m Memory: 7.64 GiB used: 1.91 GiB (25.0%) Init: systemd
v: 245 runlevel: 5 Compilers: gcc: 9.4.0 alt: 9 Client: Unknown python3.8 client
inxi: 3.0.38 ----------------------------------
--------------
kind regards all .. have a great day