Change OpenCV dependency to scikit-image

Using OpenCV in RLlib makes it much harder to install it because of the system dependencies e.g. libGL or issues with ffmpeg and libopenh264.

OpenCV is used only in a handful of places (see Search · cv2 · GitHub) for simple image transforms, but it makes setup much more tedious. Scikit-image is also better maintained, so it might be a better alternative for the future.

1 Like

Great point, thanks for the hint. Will take a look.

Hey @vakker00 , would love to do a PR for this, but could you send me the actual code-replacements for those few (2) occurences of cv2?

In particular:

        frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
        frame = cv2.resize(
            frame, (self.width, self.height), interpolation=cv2.INTER_AREA)


        img = cv2.imread(img_file).astype(np.float32)


Thanks @sven1977 for looking into this.
I think the following is equivalent:

from skimage import transform, color
frame = color.rgb2gray(frame)
frame = transform.resize(frame, (self.height, self.width))


from skimage import io
img = io.imread(img_file).astype(np.float32)

but keep in mind that CV2 loads images BGR by default, not RGB.
Currently the imread is in a test, so it doesn’t really matter how the image looks.

1 Like

Hi @sven1977
Do you have an update on this issue?
I would be happy to open a PR for this if that helps.


Edit: see CV2 to Skimage change by vakker · Pull Request #16841 · ray-project/ray · GitHub