上のコードは縦線,横線の境界線を検出するアルゴリズムですが,もう少し拡張すれば,斜めを向いている場合などでも出来そうですね.
参考文献
[1] Extracting Straight Lines
https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=4767808
J. BRIAN BURNS, ALLEN R. HANSON, MEMBER, IEEE, AND EDWARD M. RISEMAN, IEEE TRANSACTIONS ON PATTERN ANALYSIS AND MACHINE INTELLIGENCE, VOL. PAMI-8, NO. 4, JULY 1986 E
[2] LSD: a Line Segment Detector
http://www.ipol.im/pub/art/2012/gjmr-lsd/?utm_source=doi
Rafael Grompone von Gioi, J´er´emie Jakubowicz, Jean-Michel Morel, Gregory Randall Published in Image Processing On Line on 2012–03–24. Submitted