Exemple #1
0
def hough_cornering(image, orig, crop_box):  # added original for plotting
    original = image.copy(
    )  # necessary? Need to walk through these methods and see what they change
    downsized, ratio = reshape.standard_resize(image, new_width=100.0)
    edged = edging.page_edging(downsized, thresh1=0, thresh2=160)  # good
    lines = standard_hough_lines(edged)

    corners = np.zeros(shape=(4, 2))
    if len(lines) < 70:
        corners = all_corners(lines)  # TRYING THIS 4/18
    else:
        print("TOO MANY HOUGH LINES AT " + str(len(lines)))

    success = False
    filtered_corners = np.zeros(shape=(4, 2))
    upsized_filtered_corners = np.zeros(shape=(4, 2))
    if len(corners) >= 4:
        # filtered_corners, success = corner_filtration(corner_array) # old method, didn't work.
        image_area = downsized.shape[0] * downsized.shape[1]
        filtered_corners, success = corner_filter(corners,
                                                  image_area=image_area)

        upsized_filtered_corners = filtered_corners * ratio

        upsized_filtered_corners = np.int0(upsized_filtered_corners)

        xmin, xmax, ymin, ymax = boxing.max_points(crop_box)

        upsized_filtered_corners[:, 0] += xmin
        upsized_filtered_corners[:, 1] += ymin

        upsized_filtered_corners = tuple(map(tuple, upsized_filtered_corners))
    '''This works when 4 corners are passed in. Need to figure out how to filter down to 4 corners or skip it if no corners found.'''
    return upsized_filtered_corners, success
Exemple #2
0
def hough_detection(image):
    original = image.copy(
    )  # necessary? Need to walk through these methods and see what they change
    downsized, ratio = reshape.standard_resize(image, new_width=100.0)
    edged = edging.page_edging(downsized, thresh1=0, thresh2=160)  # good
    lines = standard_hough_lines(edged)

    corners = set()
    if len(lines) < 70:
        corners = all_corners(lines)  # TRYING THIS 4/18
    else:
        print("TOO MANY HOUGH LINES AT " + str(len(lines)))

    success = False
    if len(corners) >= 4:
        downsized_area = downsized.shape[0] * downsized.shape[1]
        filtered_corners, success = corner_filter(corners,
                                                  image_area=downsized_area)

    upsized_filtered_corners = filtered_corners * ratio
    upsized_filtered_corners = np.int0(upsized_filtered_corners)

    # xmin, xmax, ymin, ymax = boxing.max_points(crop_box)
    # upsized_filtered_corners[:, 0] += xmin
    # upsized_filtered_corners[:, 1] += ymin

    # upsized_filtered_corners = tuple(map(tuple, upsized_filtered_corners))
    return upsized_filtered_corners, success
Exemple #3
0
def hough_corners(image, orig, crop_box):  # added original for plotting
    original = image.copy(
    )  # necessary? Need to walk through these methods and see what they change
    downsized, ratio = reshape.standard_resize(image, new_width=100.0)
    edged = edging.page_edging(downsized, thresh1=0, thresh2=160)  # good
    lines = standard_hough_lines(edged)
    # lined = draw_lines(downsized.copy(), lines)

    corners = set()
    if len(lines) < 70:
        corners = all_corners(lines)  # TRYING THIS 4/18
    else:
        print("TOO MANY HOUGH LINES AT " + str(len(lines)))

    success = False
    if len(corners) >= 4:
        image_area = downsized.shape[0] * downsized.shape[1]
        filtered_corners, success = corner_filter(corners,
                                                  image_area=image_area)

    # upsized_corners = corners * ratio
    upsized_filtered_corners = filtered_corners * ratio

    # upsized_corners = np.int0(upsized_corners)
    upsized_filtered_corners = np.int0(upsized_filtered_corners)

    xmin, xmax, ymin, ymax = boxing.max_points(crop_box)
    # upsized_corners[:, 0] += xmin
    # upsized_corners[:, 1] += ymin
    upsized_filtered_corners[:, 0] += xmin
    upsized_filtered_corners[:, 1] += ymin

    # upsized_corners = tuple(map(tuple, upsized_corners))
    upsized_filtered_corners = tuple(map(tuple, upsized_filtered_corners))

    # cornered = draw_corners(orig, upsized_corners)
    # if success:
    # cornered = draw_corners(cornered, upsized_filtered_corners, color=(255,0,0))
    # warped = reshape.perspective_transform(image=orig, points=upsized_filtered_corners)
    # threshed = coloring.thresholding(warped)
    # functions.plot_images([orig, image, edged, lined, cornered, threshed], titles=['Original', 'Cropped', 'Canny', 'Hough lines', 'Corners', 'Transform'])
    '''This works when 4 corners are passed in. Need to figure out how to filter down to 4 corners or skip it if no corners found.'''
    return upsized_filtered_corners
Exemple #4
0
def hough_detection(image):
    # original = image.copy() # necessary? Need to walk through these methods and see what they change
    downsized, ratio = reshape.standard_resize(image, new_width=100.0)
    edged = edging.page_edging(downsized, thresh1=0, thresh2=160)  # good
    lines = standard_hough_lines(edged)

    # corners = np.zeros(shape=(4,2))
    # if len(lines) < 70:
    corners = all_corners(lines)  # TRYING THIS 4/18

    success = False
    # if len(corners) >= 4 and np.linalg.norm(corners) > 0:
    if len(corners) >= 4:
        downsized_area = downsized.shape[0] * downsized.shape[1]
        filtered_corners, success = corner_filter(corners,
                                                  image_area=downsized_area)
        corners = np.array(list(filtered_corners))
        print("original corners: " + str(corners))
        corners = corners * ratio

    print("final corners: " + str(corners))
    return corners, success
Exemple #5
0
def hough_cornering(image, orig):  # added original for plotting
    original = image.copy(
    )  # necessary? Need to walk through these methods and see what they change
    downsized, ratio = reshape.standard_resize(image, new_width=100.0)
    # edged = edging.orig_page_edging(downsized) # bad
    edged = edging.page_edging(downsized, thresh1=0, thresh2=160)  # good
    # edged = edging.auto_edging(downsized, sigma=0.5) # not great
    lines = standard_hough_lines(edged)
    lined = draw_lines(downsized.copy(), lines)

    # functions.plot_image(edged)

    corners = set()
    if len(lines) < 70:
        # corners = hough_corners(lines) # COMMENTED OUT 4/18
        print("FEWER than 30 lines...finding CORNERS")
        corners = all_corners(lines)  # TRYING THIS 4/18
        print("Here are the corners in hough cornering")
        print(corners)
    else:
        print("TOO MANY HOUGH LINES AT " + str(len(lines)))

    success = False
    if len(corners) >= 4:
        # filtered_corners, success = corner_filtration(corner_array) # old method, didn't work.
        image_area = downsized.shape[0] * downsized.shape[1]
        filtered_corners, success = corner_filter(corners,
                                                  image_area=image_area)
        print("CORNERS after corner filtration")
        print(filtered_corners)
    '''Compute bounding box size from corners. If too small, success = False. O
        OR add a check in the filtration method that ensures the range of all axes is reasonable
        Reason: came across a case where there were 4 points really close together that the logic interpreted as valid
        because it is using the global range defined in the method from the corners there '''

    upsized_corners = corners * ratio
    upsized_filtered_corners = filtered_corners * ratio

    upsized_corners = np.int0(upsized_corners)
    upsized_filtered_corners = np.int0(upsized_filtered_corners)

    upsized_corners = tuple(map(tuple, upsized_corners))
    upsized_filtered_corners = tuple(map(tuple, upsized_filtered_corners))

    # cornered = draw_corners(downsized, corners)
    cornered = draw_corners(original, upsized_corners)
    if success:
        # cornered = draw_corners(cornered, filtered_corners, color=(255,0,0))
        cornered = draw_corners(cornered,
                                upsized_filtered_corners,
                                color=(255, 0, 0))
        warped = reshape.perspective_transform(image=original,
                                               points=filtered_corners,
                                               ratio=ratio)
        threshed = coloring.thresholding(warped)
        # functions.plot_images([image, lined, cornered, threshed], titles=['Original', 'Hough lines', 'Corners', 'Transform'])
        functions.plot_images([orig, image, edged, lined, cornered, threshed],
                              titles=[
                                  'Original', 'Cropped', 'Canny',
                                  'Hough lines', 'Corners', 'Transform'
                              ])
        # functions.plot_images([original, edged, lined, cornered, threshed], titles=['Original', 'edged', 'Hough lines', 'Corners', 'Transform'])
    else:
        functions.plot_images([image, edged, lined, cornered],
                              titles=['image', 'edged', 'lined', 'cornered'])
Exemple #6
0
def hough_cornering(image, orig, crop_box):  # added original for plotting
    original = image.copy(
    )  # necessary? Need to walk through these methods and see what they change
    downsized, ratio = reshape.standard_resize(image, new_width=100.0)
    # edged = edging.orig_page_edging(downsized) # bad
    edged = edging.page_edging(downsized, thresh1=0, thresh2=160)  # good
    # edged = edging.auto_edging(downsized, sigma=0.5) # not great
    lines = standard_hough_lines(edged)
    lined = draw_lines(downsized.copy(), lines)

    # functions.plot_image(edged)

    # corners = set()
    corners = np.zeros(shape=(4, 2))
    if len(lines) < 70:
        # corners = hough_corners(lines) # COMMENTED OUT 4/18
        # print("FEWER than 30 lines...finding CORNERS")
        corners = all_corners(lines)  # TRYING THIS 4/18
        # print("Here are the corners in hough cornering")
        # print(corners)
    else:
        print("TOO MANY HOUGH LINES AT " + str(len(lines)))

    success = False
    filtered_corners = np.zeros(shape=(4, 2))
    upsized_filtered_corners = np.zeros(shape=(4, 2))
    if len(corners) >= 4:
        # filtered_corners, success = corner_filtration(corner_array) # old method, didn't work.
        image_area = downsized.shape[0] * downsized.shape[1]
        filtered_corners, success = corner_filter(corners,
                                                  image_area=image_area)
        # print("CORNERS after corner filtration")
        # print(filtered_corners)
        '''Compute bounding box size from corners. If too small, success = False. O
        OR add a check in the filtration method that ensures the range of all axes is reasonable
        Reason: came across a case where there were 4 points really close together that the logic interpreted as valid
        because it is using the global range defined in the method from the corners there '''

        # print("corners before upsizeing")
        # print(corners)
        # print(type(corners))
        upsized_corners = corners * ratio
        upsized_filtered_corners = filtered_corners * ratio

        upsized_corners = np.int0(upsized_corners)
        upsized_filtered_corners = np.int0(upsized_filtered_corners)

        xmin, xmax, ymin, ymax = boxing.max_points(crop_box)
        # print("UPSIZED CORNERS")
        # print(upsized_corners)
        # upsized_corners[:, 0] += xmin
        # upsized_corners[:, 1] += ymin

        # xmin, xmax, ymin, ymax = boxing.max_points(upsized_filtered_corners)
        # upsized_filtered_corners[:, 0] += xmin
        # upsized_filtered_corners[:, 1] += ymin

        upsized_filtered_corners[:,
                                 0] = np.add(upsized_filtered_corners[:, 0],
                                             xmin,
                                             out=upsized_filtered_corners[:,
                                                                          0],
                                             casting="unsafe")
        upsized_filtered_corners[:,
                                 1] = np.add(upsized_filtered_corners[:, 1],
                                             ymin,
                                             out=upsized_filtered_corners[:,
                                                                          1],
                                             casting="unsafe")

        # upsized_corners = tuple(map(tuple, upsized_corners))
        upsized_filtered_corners = tuple(map(tuple, upsized_filtered_corners))

    # cornered = draw_corners(downsized, corners)
    # cornered = draw_corners(original, upsized_corners)
    # cornered = draw_corners(orig, upsized_corners) # was here
    # if success:
    # cornered = draw_corners(cornered, filtered_corners, color=(255,0,0))
    # cornered = draw_corners(cornered, upsized_filtered_corners, color=(255,0,0)) # was here
    # warped = reshape.perspective_transform(image=original, points=filtered_corners, ratio=ratio)
    # warped = reshape.perspective_transform(image=orig, points=upsized_filtered_corners)
    # threshed = coloring.thresholding(warped)
    # functions.plot_images([image, lined, cornered, threshed], titles=['Original', 'Hough lines', 'Corners', 'Transform'])
    # functions.plot_images([orig, image, edged, lined, cornered, threshed], titles=['Original', 'Cropped', 'Canny', 'Hough lines', 'Corners', 'Transform']) # was here
    # functions.plot_images([original, edged, lined, cornered, threshed], titles=['Original', 'edged', 'Hough lines', 'Corners', 'Transform'])
    # else:
    # functions.plot_images([image, edged, lined, cornered], titles=['image', 'edged', 'lined', 'cornered'])    # was here
    # print('hello dolly')
    '''This works when 4 corners are passed in. Need to figure out how to filter down to 4 corners or skip it if no corners found.'''
    return upsized_filtered_corners, success