Breaking infinite loops in card image border detection