I'm looking for a way to convert a raster (bitmap) hand-drawn line to a set of vectors that approximate the path.
First of all, is there a public Java library or algorithm for this?
Specifically, given the hand-drawn black line below in bitmap format, I want the set of vectors that make up the orange line. Ideally I don't want the vector to follow the bitmap too closely. Like the orange line below, it should contain the minimum number of vertices that follow the line within some configurable margin of error.
Thanks in advance!
Imagetracer is a free and open source (Public Domain) library and application which might be useful. Disclaimer: I made this.
https://github.com/jankovicsandras/imagetracerjava
You can get an object with path coordinates like this:
import jankovicsandras.imagetracer.ImageTracer;
...
HashMap<String,Float> options = new HashMap<String,Float>();
options.put( "ltres", 2f ); // Linear error treshold
options.put( "qtres", 2f ); // Quadratic spline error treshold
IndexedImage myimage = ImageTracer.imageToTracedata( "input.jpg", options, null );
ArrayList<ArrayList<ArrayList<Double[]>>> mylayers = myimage.layers;
... process coordinates in mylayers
where
ArrayList<ArrayList<ArrayList<Double[]>>> layers
means roughly
ArrayList of color layers < ArrayList of paths < ArrayList of line segments < double x, y, type:straight or quadratic spline > > >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With