alyssaq / face_morpher

:angel: Morph faces with Python, Numpy, Scipy
882 stars 233 forks source link

Image RGB array must be uint8 or floating point; found int32 #61

Open ivan-uskov opened 4 years ago

ivan-uskov commented 4 years ago

When using background=average, got this:

root@bfa4a21e5b8e:/app# python face_morpher/facemorpher/averager.py --work=/app/work/tmp/avg --out=work/result/1.png --background=average <class 'numpy.ndarray'> Averaged 3 work Image RGB array must be uint8 or floating point; found int32

Guml commented 4 years ago

change

plt = plotter.Plotter(plot, num_images=1, out_filename=out_filename) plt.save(dest_img)

to: plt = plotter.Plotter(plot, num_images=1, out_filename=out_filename) dest_img = dest_img.astype(np.uint8) plt.save(dest_img)

from: https://stackoverflow.com/questions/42044259/getting-black-plots-with-plt-imshow-after-multiplying-image-array-by-a-scalar

nchlis commented 4 years ago

Guml's answer above works. Just don't forget to add "import numpy as np" in averager.py since it is not included by default.

JonBoyleCoding commented 3 years ago

This issue stems from the call to the locater here: https://github.com/alyssaq/face_morpher/blob/7a30611cd9d33469e843cec9cfa23ccf819386a8/facemorpher/averager.py#L103

The locator.average_points returns an int32 type as defined here: https://github.com/alyssaq/face_morpher/blob/7a30611cd9d33469e843cec9cfa23ccf819386a8/facemorpher/locator.py#L91-L97

The version of matplotlib uses requires it to be a uint8 when attempting to save the plot - hence the raised exception.