Short post, just notes really. Been tinkering with image segmentation using opencv and the rust-bindings and specifically the hfs feature. Image Segmentation is creating regions in an image that somehow belong together, like the region of a bird in a bigger picture of two birds on a nest. See also here.
Installing opencv is easy, most of the time. Did have troubles on windows in the past, but at least on mac, it’s just brew install opencv
Next, working from rust is also easy using the opencv crate.
There was no hello-world type example for working with HFS in rust, (only c++), so here’s one:
|
|
The <dyn HfsSegment>::create
command is slightly odd, but HfsSegment is a trait and create
is an associated function on it. The rest is pretty straighforward, if you know opencv.
The documentation is pretty short. I haven’t figured out what the parameters mean. But playing with them you will get different results.
Results:
input
output
image from https://en.wikipedia.org/wiki/Image
NB. The authors state that you shouldn’t use perform_segment_cpu
, but perform_segment_gpu
instead, but that would require cuda. So use that if you are going to use it for real (because that is much faster, the cpu version does let you wait seconds (depending on image size/parameters of course)).