6.1 MiB
6.1 MiB
Finding corners, tested on several images¶
It turns out the cosine_threshold is quite tricky, maybe it should be searched for as the lowest or a reasonably low veresion such that exactly two lines are found per corner. Also, it might help to force overlap of two out ofthree points when clusting points that lie on one line.
In [8]:
import sys sys.path.append('..') from pagelocalizer import find_corner_circles, cluster_circles_per_corner, intersection_per_corner, separate_lines, find_line_coefficients_per_corner import numpy import glob import cv2 %matplotlib inline from matplotlib import pyplot, rcParams rcParams['figure.figsize'] = (20, 16) rcParams['figure.dpi'] = '100'
In [10]:
for filename in ['../images/img2.jpg', '../images/img4.jpg']: im = cv2.imread(filename, cv2.IMREAD_COLOR) pyplot.figure() pyplot.imshow(im) keypoints = find_corner_circles(im, area=(5000 / 4, 5000 * 4), color=None, convexity=0.9, circularity=0.7, inertia=None, thresholdstep=1 ) keypoints, corner_circles = cluster_circles_per_corner(keypoints, distance_factor=1.5) for corner in corner_circles: pyplot.plot(*zip(*[keypoints[i].pt for i in corner]), 'o', markersize=12, fillstyle='none', markeredgewidth=2) lines_per_corner = find_line_coefficients_per_corner( keypoints, corner_circles, cosine_threshold=0.00137046524) xx = numpy.arange(0, im.shape[1]-1,0.25) for (a, b), (c, d) in lines_per_corner: pyplot.plot(xx, a*xx + b, linewidth=4) pyplot.plot(xx, c*xx + d, linewidth=4) corners, order = intersection_per_corner(lines_per_corner) polygon_corners = numpy.array([corners[i] for i in order] + [corners[order[0]]]) pyplot.plot(*polygon_corners.T, 'r-', linewidth=4) pyplot.imshow(im) pyplot.axis('off')