TomWhitwell / SlowMovie

MIT License
342 stars 67 forks source link

Support for the grey scales on waveshare screens (10.3") #147

Closed simonjowett closed 1 year ago

simonjowett commented 1 year ago

Hi, Fistly I'd like to confirm that the repo works on the waveshare 10.3" screen. Maybe that can be added to your already extensive list?

The images are good, at the same time I'd like to take advantage of the 16 grey scales that this screen offers. I can see that the omni-epd IT8951 driver provides this support (ref line below in waveshare_display.py)

 self._device.draw_full(self.it8951_constants.DisplayModes.GC16)

The test utility image also shows a full grey scale image.

I have also successfully tested the repo https://github.com/szantaii/slow-movie-frame-10.3 which plays slow movies specifically for this screen but lack some of the other features your repo offers.

I'm unsure as to what changes would need to be made and there for how much effort it would take. I'm guessing it is in the image manipulation, dithering and file saving where the changes would need to be made?

robweber commented 1 year ago

Thanks for the comment. The omni-epd repo just received a similar request for IT8951 devices. There is a fix in the works to add grayscale support for these devices. Once it's confirmed working it will get merged in and work for SlowMovie as well. If you have time to test the new branch on your own display and confirm it works that would help speed this along as well.

simonjowett commented 1 year ago

If you have time to test the new branch on your own display and confirm it works that would help speed this along as well.

Hi Rob

I've tried but I think I'm missing a key step as it's failing. This is the process I ran through:

I've cloned the repo and set the branch to it8951_greyscale

pi@veryslowmovie:~/omni-epd $ git branch -a
* it8951_greyscale
  main
  remotes/origin/HEAD -> origin/main
  remotes/origin/it8951_greyscale
  remotes/origin/main
  remotes/origin/numpy_fix

I then ran the 2 commands

cd omni-epd
sudo pip3 install --prefer-binary .

I then modified the cofiguration file in my SlowMovie directory to add the line


[EPD]
mode=gray16

[Display]
flip_horizontal=True

However this throws an error for the gray16

May 07 13:03:13 veryslowmovie systemd[1]: Started Slow Movie Player Service.
May 07 13:03:20 veryslowmovie python3[620]: Traceback (most recent call last):
May 07 13:03:20 veryslowmovie python3[620]:   File "/home/pi/SlowMovie/slowmovie.py", line 264, in <module>
May 07 13:03:20 veryslowmovie python3[620]:     epd = displayfactory.load_display_driver(args.epd)
May 07 13:03:20 veryslowmovie python3[620]:   File "/home/pi/.local/lib/python3.9/site-packages/omni_epd/displayfactory.py", line 117, in load_d>
May 07 13:03:20 veryslowmovie python3[620]:     raise EPDConfigurationError(displayName, "mode", result.mode)
May 07 13:03:20 veryslowmovie python3[620]: omni_epd.errors.EPDConfigurationError: 'gray16' for 'mode' is not a valid configuration value for wa>
May 07 13:03:20 veryslowmovie systemd[1]: slowmovie.service: Main process exited, code=exited, status=1/FAILURE
May 07 13:03:20 veryslowmovie systemd[1]: slowmovie.service: Failed with result 'exit-code'.
May 07 13:03:20 veryslowmovie systemd[1]: slowmovie.service: Consumed 6.230s CPU time.

I also used the test sample and it throws up a similar error

pi@veryslowmovie:~/omni-epd/examples/ini_file_example $ python3 draw_image.py
Loading display
Traceback (most recent call last):
  File "/home/pi/omni-epd/examples/ini_file_example/draw_image.py", line 37, in <module>
    epd = displayfactory.load_display_driver()
  File "/home/pi/.local/lib/python3.9/site-packages/omni_epd/displayfactory.py", line 117, in load_display_driver
    raise EPDConfigurationError(displayName, "mode", result.mode)
omni_epd.errors.EPDConfigurationError: 'gray16' for 'mode' is not a valid configuration value for waveshare_epd.it8951

Any ideas? I'm not very experienced at 'building' and 'making' repos, perhaps I missed a step?

robweber commented 1 year ago

My guess is that you created a local version of the branch but didn't pull in the changes from Github. From your it8951_greycale branch what happens if you do a git pull command? On a clean clone of the repo I did the following and got the correct changes to come down:

~/Git/omni-epd$ cd omni_epd
~/Git/omni-epd$ git checkout -b it8951_greyscale
~/Git/omni-epd$ git branch --set-upstream-to=origin/it8951_greyscale it8951_greyscale
~/Git/omni-epd$ git pull
Updating 66a33a1..c1a3fb3
Fast-forward
 src/omni_epd/displays/waveshare_display.py | 4 ++++
 1 file changed, 4 insertions(+)

~/Git/omni-epd$ git branch -vv

* it8951_greyscale c1a3fb3 [origin/it8951_greyscale] use consistant spelling of "gray"
  main             66a33a1 [origin/main] updated Changelog and README for new functionality

From there attempt to rebuild the library. You'll probably have to remove the one you currently built sudo pip3 uninstall omni_epd first. Hopefully this helps.

simonjowett commented 1 year ago

ok , i uninstalled omni-epd then followed the commands above (except i did not do a clean clone as I don't know what that is). See below.

pi@veryslowmovie:~/omni-epd $ git checkout -b it8951_greyscale
fatal: A branch named 'it8951_greyscale' already exists.
pi@veryslowmovie:~/omni-epd $ git branch --set-upstream-to=origin/it8951_greyscale it8951_greyscale
Branch 'it8951_greyscale' set up to track remote branch 'it8951_greyscale' from                'origin'.
pi@veryslowmovie:~/omni-epd $ git pull
hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint:
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
Already up to date.
pi@veryslowmovie:~/omni-epd $ git branch -vv
* it8951_greyscale c1a3fb3 [origin/it8951_greyscale] use consistant spelling of                "gray"
  main             66a33a1 [origin/main] updated Changelog and README for new fu               nctionality
pi@veryslowmovie:~/omni-epd $ sudo pip3 install --prefer-binary .
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Processing /home/pi/omni-epd
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting IT8951@ git+https://github.com/GregDMeyer/IT8951
  Cloning https://github.com/GregDMeyer/IT8951 to /tmp/pip-install-sco89_2y/it89               51_4dcf9d4e74b84dff82aa87de790cbf64
  Running command git clone -q https://github.com/GregDMeyer/IT8951 /tmp/pip-ins               tall-sco89_2y/it8951_4dcf9d4e74b84dff82aa87de790cbf64
Collecting waveshare-epd@ git+https://github.com/waveshare/e-Paper.git#subdirect               ory=RaspberryPi_JetsonNano/python&egg=waveshare-epd
  Cloning https://github.com/waveshare/e-Paper.git to /tmp/pip-install-sco89_2y/               waveshare-epd_f4c4fb0fc8c74a01adc7b0c5e951ff8a
  Running command git clone -q https://github.com/waveshare/e-Paper.git /tmp/pip               -install-sco89_2y/waveshare-epd_f4c4fb0fc8c74a01adc7b0c5e951ff8a
Requirement already satisfied: inky[rpi]>=1.3.1 in /usr/local/lib/python3.9/dist               -packages (from omni-epd==0.3.4b1) (1.5.0)
Requirement already satisfied: Pillow>=9.1.0 in /usr/local/lib/python3.9/dist-pa               ckages (from omni-epd==0.3.4b1) (9.5.0)
Requirement already satisfied: RPi.GPIO in /usr/lib/python3/dist-packages (from                waveshare-epd@ git+https://github.com/waveshare/e-Paper.git#subdirectory=Raspber               ryPi_JetsonNano/python&egg=waveshare-epd->omni-epd==0.3.4b1) (0.7.0)
Requirement already satisfied: spidev in /usr/lib/python3/dist-packages (from wa               veshare-epd@ git+https://github.com/waveshare/e-Paper.git#subdirectory=Raspberry               Pi_JetsonNano/python&egg=waveshare-epd->omni-epd==0.3.4b1) (3.5)
Requirement already satisfied: smbus2 in /usr/local/lib/python3.9/dist-packages                (from inky[rpi]>=1.3.1->omni-epd==0.3.4b1) (0.4.2)
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (from ink               y[rpi]>=1.3.1->omni-epd==0.3.4b1) (1.19.5)
Building wheels for collected packages: omni-epd
  Building wheel for omni-epd (PEP 517) ... done
  Created wheel for omni-epd: filename=omni_epd-0.3.4b1-py3-none-any.whl size=15               16099 sha256=2cd0ea508bcb7782d7f26178c4a51cff02f740e406e56f299af6e66625f562a1
  Stored in directory: /root/.cache/pip/wheels/2b/32/39/72d3401b8f86873ee6654f72               b19acf4c8e298897c992be2719
Successfully built omni-epd
Installing collected packages: omni-epd
Successfully installed omni-epd-0.3.4b1
pi@veryslowmovie:~/omni-epd $

Unfortunately the slowmovie player no longer works at all. Doh! (no error message but the log does not update so something is not happy!

EDIT****

I've got the same error when using the command

''' pi@veryslowmovie:~/SlowMovie $ python3 slowmovie.py Traceback (most recent call last): File "/home/pi/SlowMovie/slowmovie.py", line 264, in epd = displayfactory.load_display_driver(args.epd) File "/home/pi/.local/lib/python3.9/site-packages/omni_epd/displayfactory.py", line 117, in load_display_driver raise EPDConfigurationError(displayName, "mode", result.mode) omni_epd.errors.EPDConfigurationError: 'gray16' for 'mode' is not a valid configuration value for waveshare_epd.it8951

simonjowett commented 1 year ago

Just another thought. I can see the 'fatal' error early on and wonder if there is another step to do after the uninstall step. The uninstall step did not seem to remove the files/folders.

robweber commented 1 year ago

How did you install SlowMovie - using the helper install script? That installs libraries under your local user instead of in the system directory (ie, via sudo). Normally local packages take precedence over system package so it's possible you're still loading the "production" version of omni-epd.

Do a combination of

cd ~
sudo pip3 uninstall omni-epd
pip3 uninstall omni-epd

After that run this command to see if omni-epd is installed anywhere. It should return nothing, if you see an entry it means an install is still lurking about.

sudo pip3 freeze | grep omni-epd

After this re-building should re-install and you won't have any conflicts. Running dev versions of stuff is a bit of a headache sometimes, thanks for going through the effort.

simonjowett commented 1 year ago

ok - I performed the 'double' removal with your commands above. I then performed the 'grep'command and nothing was returned - good!

I then called for a clone of the repository and it complained the omni-epd folder (and all the files) were existing. I decided to

rm -r omni-epd

which seemed to delete them. I then proceeded to clone and follow the commands above to checkout, then pull relevant branch. I then rebuilt the repo with the command

sudo pip3 install --prefer-binary .

all responses looked ok and no errors were reported.

I then modified the omni-epd.ini file in the SlowMovie folder to have the "mode=gray16"

[EPD]
mode=gray16

[Display]
flip_horizontal=True

I then ran the command

python3 slowmovie.py

No errors were given and an image was displayed. Unfortunately it still looks like dithered b&w!

Are there any other settings to change?

Sorry this image is upside down - its from the test.mp4 file

b w

I tried to run the test in the examples folder but this throws up the error I got before:

pi@slowmovie:~/omni-epd/examples/mode_example $ python3 draw_image.py
Loading display
Traceback (most recent call last):
  File "/home/pi/omni-epd/examples/mode_example/draw_image.py", line 38, in <module>
    epd = displayfactory.load_display_driver(displayName)
  File "/usr/local/lib/python3.9/dist-packages/omni_epd/displayfactory.py", line 117, in load_display_driver
    raise EPDConfigurationError(displayName, "mode", result.mode)
omni_epd.errors.EPDConfigurationError: 'gray16' for 'mode' is not a valid configuration value for omni_epd.mock
simonjowett commented 1 year ago

For further info here is my slowmovie.conf

random-frames = True
delay = 120
increment = 4
contrast = 1.0
epd = waveshare_epd.it8951
fullscreen = True
random-file = True
robweber commented 1 year ago

Based on your tests I reviewed the changes in the branch again and noticed something was missing. It was indeed applying the bw filter even when using the gray16 mode option. I've fixed this but you'll have to git pull, uninstall the current, and rebuild to get the changes.

The error in the drawimage example is expected since gray16 isn't a mode for the virtual EPD device (omni_epd.mock). If you want to run an example you can use the omni-epd-test utility as described in the README for more consistent results. You'll need to run it from the directory that contains your omni-epd.ini file for it to load the right settings.

Thanks for testing this out!

simonjowett commented 1 year ago

ok - I tried again and it seems to work!

I tried with and without dithering but dithering seems to bring back the spoti-ness in the image. What are your thoughts?

robweber commented 1 year ago

Awesome - glad to know the new gray16 mode is working. I can get that merged in.

Regarding the dithering - what kind of dithering are you using? There are tons of options. Some probably have a better effect than others depending on the type of image. When in BW mode there is a FloydSteinberg dither applied by default because Pillow has to use something when going from color to bw. You could try a different method if that's not having good results.

simonjowett commented 1 year ago

I just tried the FloydSteinberg, with no other arguments or options. The image quality seemed to go backwards significantly. There must be a technique/settings that should work for 16 gray scale images, but after reading all the info and instructions my head started to spin and (for me) it may be a case of trial and error to find a good set of parameters.

robweber commented 1 year ago

I've got this merged in to omni-epd - thanks for testing.