Exemplo n.º 1
0
def pipeline(image):
    orig = image.copy()
    downsized, ratio = functions.standard_resize(image, new_width=100.0)
    edged = functions.small_page_edging(downsized)
    processed = functions.closed_inversion(edged)
    boxes = functions.box_generation(processed)
    filtered_boxes = functions.box_filtration(boxes)

    detected = downsized.copy()
    rects = []
    if not filtered_boxes:
        # print "FOUND NO BOXES; TRYING DIFFERENT CANNY"
        # edged = functions.text_edging(orig.copy())
        # edged = functions.downsized_text_edging(downsized.copy())
        edged = functions.smaller_page_edging(downsized)
        # rotated = hough.prob_hough_rotation(edged, orig.copy())
        # detected = rotated
        processed = functions.closed_inversion(edged)
        boxes = functions.box_generation(processed)
        filtered_boxes = functions.box_filtration(boxes)
        final_box = functions.merge_boxes(filtered_boxes)
        if final_box:
            # final_box = final_box * ratio
            final_box = box[:, :] * ratio
            final_box = np.round(small_box)
            final_box = small_box.astype(int)

            warped = functions.perspective_transform(orig.copy(),
                                                     final_box,
                                                     ratio=ratio)
            lined = hough.standard_hough(warped)
        else:
            print("in demo pipeline")

    else:
        for box in boxes:
            # print box
            detected = cv2.drawContours(detected, [box], 0, (0, 255, 0), 1)
            rects.append(cv2.minAreaRect(box))
            # print "rect in alternate_rect_attempt: " + str(cv2.minAreaRect(box))
        if len(boxes) > 1:
            # print "got more than 1 box, attempting merge"
            merged = functions.merge_boxes(boxes)
            detected = cv2.drawContours(detected, [merged], 0, (255, 0, 0), 2)
    functions.plot_images(
        [edged, processed, detected],
        ["Edge Detection", "Morphological Operations", "Contour Finding"])
    return detected
Exemplo n.º 2
0
def alternate_rect_attempt(image):
    orig = image.copy()

    # <---- RESIZING -----> #
    image, ratio = functions.standard_resize(image, new_width=100.0)
    # <---- RESIZING -----> #

    # edged = functions.colorOps(image)
    edged = functions.page_edging(image)
    processed = functions.closed_inversion(edged)
    boxes = functions.alternateRectMethod(processed)
    functions.boxes_comparison(image=processed, boxes=boxes)

    detected = image.copy()
    rects = []
    for box in boxes:
        # print box
        detected = cv2.drawContours(detected, [box], 0, (0, 255, 0), 1)
        rects.append(cv2.minAreaRect(box))
        # print "rect in alternate_rect_attempt: " + str(cv2.minAreaRect(box))
    # utility.IOU(rects[0], rects[1])
    if len(boxes) > 1:
        # print "got more than 1 box, attempting merge"
        merged = functions.merge_boxes(boxes)
        detected = cv2.drawContours(detected, [merged], 0, (255, 0, 0), 2)
    functions.plot_images(
        [edged, processed, detected],
        ["Edge Detection", "Morphological Operations", "Contour Finding"])
Exemplo n.º 3
0
def boxes_from_edged(image, edging_function, **edging_args):
    edged = edging_function(
        image, **edging_args
    )  # perform edge detection on the input image according to the passed in edging function
    closed_invert = functions.closed_inversion(
        edged
    )  # perform closed inversion (morphological closing + color inversion) on the edged image
    boxes = functions.box_generation(
        closed_invert
    )  # generate bounding boxes from the closed inversion output
    boxes = functions.box_filtration(boxes, image.shape[1],
                                     image.shape[0])  # filter bounding boxes
    merged = functions.merge_boxes(boxes)
    return merged, boxes, edged, closed_invert