pi-top / pi-top-Python-SDK

pi-top's Python SDK (pitop package)
Apache License 2.0
27 stars 4 forks source link

[Request] Remove OpenCV requirement from the core for 300MB #582

Open m-roberts opened 1 year ago

m-roberts commented 1 year ago

Problem or Possibility

Currently OpenCV is installed with the core of the SDK, but it appears to only be used by ImageFunctions.convert Removing this dependency from the core would help to reduce install footprint for core functionality.

It is used in pitop.processing and pitop.camera, but - most importantly - it does the heavy lifting of the miniscreen's display_image function.

Proposed Solution

An OpenCV image is unlikely to be passed in without the cv2 dependency being installed, so it shouldn't even be necessary to invoke the convert function anyway.

Perhaps the display_image function could try to convert if the image format is PIL and raises an exception if it's an OpenCV image without the dependency installed?

Alternative Solutions

According to this, this operation should also work:

x = x[...,::-1].copy()

However, this does not have OpenCV's speed benefit. Perhaps this can be used as a fallback option if OpenCV is not available?

Additional Context

m-roberts commented 1 year ago

Turns out OpenCV adds an extra 171 packages accounting for ~300MB of the install size: https://pastebin.com/3czP6DWc

hramrach commented 1 year ago

Yes, the requirement to install 3 different image processing frameworks for the ability to power off the device is kind of lame.

I suspect this is due to bad design of the python libraries. Why do you need to import ImageFunctions.convert?

Can't the conversion function be a method on each image object? Then you would call the method of whichever library provided the image, transparently.

m-roberts commented 1 year ago

@jcapona @olivierwilkinson @angusjfw - any chance of someone taking a look at this? 🤔