fookatchu / pyphotonfile

Library for reading and writing files for the Anycubic Photon 3D-Printer (.photon and .cbddlp)
GNU General Public License v3.0
24 stars 9 forks source link

Compatibility with Elegoo Mars? #8

Closed yaqwsx closed 4 years ago

yaqwsx commented 5 years ago

Hello,

I want to use your library for Elegoo Mars as the internet resources claim the file format is exactly the same. However, in my project (https://github.com/yaqwsx/ElegooMarsUtilitiy) I observe two problems:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2515, in fromarray
    mode, rawmode = _fromarray_typemap[typekey]
KeyError: ((1, 1), '<i8')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./elegoUtil.py", line 54, in <module>
    cli()
  File "/home/xmrazek7/.local/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/xmrazek7/.local/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/xmrazek7/.local/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/xmrazek7/.local/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/xmrazek7/.local/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "./elegoUtil.py", line 48, in dump
    photon.export_images('tempdir')
  File "/home/xmrazek7/.local/lib/python3.7/site-packages/pyphotonfile/photonfile.py", line 277, in export_images
    self.export_image(i, os.path.join(dirpath, '{0:05d}.png'.format(i)))
  File "/home/xmrazek7/.local/lib/python3.7/site-packages/pyphotonfile/photonfile.py", line 284, in export_image
    Image.fromarray(img).convert('RGB').save(filepath)
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2517, in fromarray
    raise TypeError("Cannot handle this data type")
TypeError: Cannot handle this data type

Both of them can be reproduced by running them on input.zip

Am I using your library wrong or is there some kind of compatibility issue?

fookatchu commented 5 years ago

While the Photon-format is essentially the cbddlp-format, there are some slight differences. As far as I understood the elegoo mars uses that format. I am currently working on the next version which is nearly complete, but needs some additional testing and fixes. This version will be compatible with the cbddlp-format. You can check out the development branch if you are interessted. Otherwise I will try to finish the next version in the next days, but I currently don't have a lot of time, so no promises. Unfortunately this will came with some breaking changes for the lib, but nothing complicated. During testing I will also try to replicate and fix your problem.

fookatchu commented 5 years ago

I released v0.2.0 with support for the generic cbddlp and therefore elegoo mars format. I did try to import and export your model and that worked. I did not try to modify the image directly like you did in your code. Could you please test your code against the new version? If you still have a problem, let me know and I will look into this a bit more.

yaqwsx commented 5 years ago

The new file format seems to work well, thank you! At least for the compensate command in my utility.

However, when I call the dump command, I get:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2515, in fromarray
    mode, rawmode = _fromarray_typemap[typekey]
KeyError: ((1, 1), '<i8')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./elegoUtil.py", line 57, in <module>
    cli()
  File "/home/xmrazek7/.local/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/xmrazek7/.local/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/xmrazek7/.local/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/xmrazek7/.local/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/xmrazek7/.local/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "./elegoUtil.py", line 51, in dump
    photon.export_images('tempdir')
  File "/usr/local/lib/python3.7/dist-packages/pyphotonfile-0.2.0-py3.7.egg/pyphotonfile/photonfile.py", line 381, in export_images
  File "/usr/local/lib/python3.7/dist-packages/pyphotonfile-0.2.0-py3.7.egg/pyphotonfile/photonfile.py", line 388, in export_image
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2517, in fromarray
    raise TypeError("Cannot handle this data type")
TypeError: Cannot handle this data type

Also, could you help me to understand the new file format? Do I understand correctly that the images are still encoded in black & white, however, there are AA-level of them per layer? And the printer displays them one after other for 1/AA-level*exposure-time?

fookatchu commented 5 years ago

Did you install pillow as the PIL alternative or PIL directly? Maybe this is a version conflict. I never experienced this problem and the "export_images" method is basically used in all my test code. Could you try the Pillow version shown in the requirements.txt and let me know if this is the problem?

And regarding the layer / sublayers. I will write a quick rundown for the main README.md, but the gist is that you have in the basic 'anti-aliasing=1' setting one image for each layer. If you have an anti-aliasing level of 2, you have two images for each layer, which get illuminated directly after each other. I changed the internal layers to always have at least 1 sublayer so that the code does not have to distinguish between anti aliasing and not. Having said that, I have no clue about the elegoo mars and anti-aliasing :).

yaqwsx commented 5 years ago

This is the result of pip3 freeze freeze.txt

Thank you for the clarification - the most important part is that I can use binary erosion in my utility.

BTW: Would you mind updating the library on PIP so I can put is as a dependency of my project?

fookatchu commented 5 years ago

Strange. Give me a day and I will look further into this. The pip version will be released once this version proves to be stable and no new issues surface. I am hoping for 1-2 weeks.

fookatchu commented 5 years ago

I cloned and installed your tool in a new venv with python 3.7. I also installed pyphotonfile according to your manual. I then installed all missing dependencys. The resulting packages according to pip freeze are:

Click==7.0
cycler==0.10.0
decorator==4.4.0
imageio==2.5.0
kiwisolver==1.1.0
matplotlib==3.1.1
networkx==2.3
numpy==1.17.2
Pillow==6.1.0
pyparsing==2.4.2
pyphotonfile==0.2.0
PySide2==5.13.1
python-dateutil==2.8.0
PyWavelets==1.0.3
scikit-image==0.15.0
scipy==1.3.1
shiboken2==5.13.1
six==1.12.0

The dump command works perfectly fine! Your packages show that you have installed Pillow==5.4.1 while I have Pillow==6.1.0 installed. This could be the problem. Would you mind trying that out? Anyway, nice seeing the lib used for something else than my work :)

fookatchu commented 4 years ago

I suspect that eveything is working now. If not, please let me know. I will close this for now.

yaqwsx commented 4 years ago

Do you consider the version 0.2 as tested enough? When do you plan to release it on pypi?