Here is a small patch that adds an autorotation
algorithm to potrace. Basically, it tries to guess at
which angle the image looks the most "upright" based on
horizontal and vertical lines in the image. It works
best for things like sheet music and schematics with
many horizontal and vertical lines.
Some of the parameters may need tweaking (namely the
THRESHOLD_DEG parameter), and the algorithm should
probably be much more selective about which curves it
analyzes, but that'll come another time.
Patch against potrace 1.5