groundlight / framegrab

Library to easily grab frames from cameras or streams and do simple local analysis
MIT License
18 stars 0 forks source link

Returning frames as PIL images #37

Open timmarkhuff opened 6 months ago

timmarkhuff commented 6 months ago

Previously, FrameGrab has always returned numpy arrays. This PR changes FrameGrab to return PIL images instead.

numpy arrays can be challenging because they don't contain any metadata about color space, and therefore it's easy to mix up RGB and BGR. PIL images contain a mode attribute that fixes this usability problem.

We believe users will appreciate receiving PIL images. If they need a numpy array, they can easily convert.

This will be a breaking change, and I'm not sure if there is a way to avoid this. We could leave the old grab method the way it is, returning numpy arrays, and then create a new method called grab_frame (or something similar) that returns PIL images, but I don't believe this works towards our ultimate goal of deprecating numpy images; people will gravitate towards grab because it's simpler and probably the first thing autocomplete serves them. Maybe we could log a warning when people use grab and deprecate it in the future? However this leaves us with grab_frame as our main method, which is not as elegant as just grab.

timmarkhuff commented 6 months ago

ns a PIL image. Too much stuff would break.

Also aren't there some docs we should update for this? I think we should recommend to people to star tusing the grabimg method.

Sure, I can update the docs. Should we log a warning when someone uses grab and then eventually deprecate it? Or maybe we just offer two methods?

robotrapta commented 6 months ago

I think we just offer two, and recommend the PIL image as being simple and more reliable.