Line detection PR #2 follow-up.

This PR includes #2 rebased on top of current HEAD + a commit that cleans up the code and adds an improved adaptive thresholding routine.
Whatta hell is going on here? We are using both argparse and sys.argv? In any case, I think import argparse and import sys should go under ifmain.