tatarize / potrace

Pure Python Port of Potrace
GNU General Public License v2.0
93 stars 15 forks source link

bm_to_pathlist stuck in an infinite loop #3

Closed cabanmichal closed 2 years ago

cabanmichal commented 2 years ago

Hi,

I'm trying to trace an image of an ECG curve however the code below never finishes. It seems that the findnext function is always returning the same tuple and therefore the infinite loop in bm_to_pathlist never breaks. I'm not sure if the issue is in my code or in the package.

Thank you.

import numpy as np
import potrace
from PIL import Image

img = Image.open("curve.png")
img = img.convert("P", dither=Image.NONE)

data = np.asarray(img)
bitmap = potrace.Bitmap(data)
path = bitmap.trace()

curve

dovewi commented 2 years ago

same

tatarize commented 2 years ago

I tried potracer -o e.svg ekg.png and it finished correctly and instantly. I guess I'll try your script there.

tatarize commented 2 years ago

Yeah, okay, that did it. Lemme check up on that.

tatarize commented 2 years ago

Yeah, when I convert to "1" rather than P it works. So it's something about the code using the palette type and expecting something else that's breaking this.

tatarize commented 2 years ago

Yeah, wasn't expecting an int8 numpy array there. It reacted really strangely and could actually invert etc. It's corrected now.