With that said, the dependency on OpenCV seems entirely overkill. Surely Pillow would be a much more sensible dependency (with ImageDraw), as all you're doing with this package is drawing rectangles and labels, rather than handling any CV tasks?
For users of this library, OpenCV is pretty likely to already be installed anyway.
Another couple of reasons - OpenCV in my experience handles nonstandard images much better than Pillow (eg many channels, >8 bit). It also has a uniform Python/C++ interface so this could easily be ported if desired. I maintain a C++/Qt desktop annotation app and this would definitely be something to crib from for visualisation. Although in this case image loading could be done somewhere else and the library could just take a Numpy array.
Edit: turns out it's possible with a few extra steps, but it's not trivial. You need to handle ascender/descenders, etc: https://stackoverflow.com/questions/43060479/how-to-get-the-....
OpenCV will tell you the bbox of what it just drew.
I could've definitely used Pillow, but is there any tangible advantage to using Pillow over OpenCV?
Having OpenCV as a dependency means that if a project isn't already using OpenCV, this fairly minor (in terms of scale of functionality) utility library has a lot of baggage.
In terms of convolution of implementing it, there may be a little more effort in terms of figuring some offsets (e.g., path widths may extend bounds), but it shouldn't be anything excessive I don't think.
More useful to me would be something similar that operates on tensors on the GPU.
Doing image annotations on host/CPU often becomes a bottleneck.
The most resource heavy bit is text rendering I guess, but that could be cached per class-name and reduced to a memcopy. Otherwise drawing rectangles is pretty quick on a CPU to the point where I'd imagine the memory transfer to the GPU is probably comparable to the draw ops?
I've got OpenCV down to around 10ms per image (single thread, python) without the caching idea I mentioned above.
Thank you for the comment!
I seriously don't get it. Have we become so incapable that we can't draw rectangles and labels anymore by our self?
However, positioning the label to be exactly above the bounding box can be a little finicky. This just takes care of the math that you'd have to do to place it right above the box. I agree that I am not doing something revolutionary with the math here, but these functions are something that I've had to use over and over again and thought it would be nice to package the whole thing. This library abstracts everything behind two main functions.
There are also a few different visualizations that you can use.
Don't get me wrong, I like that you published it and I encourage it as much as I can. But if someone is capable of running complex object detection algorithms, they surely can position a label correctly without the need for another library?! This is just a couple of lines of code you can write without even thinking much about it.
Maybe I'm just out of touch, but it's so weird to me that people out there might find this useful.
Either way, your comments might be against HN guidelines .
Instead of down votes, I hope someone can answer my questions.