Esempio n. 1
0
def standard_resize(image):
    # <---- RESIZING -----> #
    height, width = image.shape[:2]
    new_width = 100.0
    scaling_factor = new_width / width
    ratio = 1 / scaling_factor
    return imutils.resize_new(image, scaling_factor=scaling_factor)
Esempio n. 2
0
def standard_resize(image, new_width = 100.0, return_ratio = True):
        # <---- RESIZING -----> #
    height, width = image.shape[:2]
    # print( "initial height, width is : " + str(height) + " " + str(width)
    # new_width = 100.0
    print("std_resize width, height: " + str(width) + ", " + str(height))
    scaling_factor = new_width/width
    ratio = 1/scaling_factor
    resized = imutils.resize_new(image, scaling_factor = scaling_factor)
    # print( "resized height, width is : " + str(resized.shape[0]) + " " + str(resized.shape[1]) + " with area " + str(resized.shape[0]*resized.shape[1])
    if return_ratio:
        return resized, ratio
    else:
        return resized
Esempio n. 3
0
    # kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(MORPH,MORPH))
    # dilated = cv2.dilate(gray, kernel)

    kernel = np.ones((15, 15), np.uint8)

    opening = cv2.morphologyEx(blurred, cv2.MORPH_OPEN, kernel)
    dilation = cv2.dilate(blurred, kernel, iterations=1)
    dilate_bordered = cv2.dilate(bordered, kernel, iterations=1)
    # dilate_edged = cv2.Canny(dilation, 0, CANNY, apertureSize = 3) # this is the original from this process

    # <---- RESIZING -----> #
    height, width = dilation.shape[:2]
    new_width = 100.0
    scaling_factor = new_width / width
    ratio = 1 / scaling_factor
    dilation_small = imutils.resize_new(dilation,
                                        scaling_factor=scaling_factor)
    bd_small = imutils.resize_new(dilate_bordered,
                                  scaling_factor=scaling_factor)
    # <---- RESIZING -----> #
    dsb = cv2.copyMakeBorder(
        dilation_small, 1, 1, 1, 1, cv2.BORDER_CONSTANT, value=[
            0, 0, 0
        ])  # added this 11/2/17. Trying to work with document occlusion.

    # dilate_large = cv2.Canny(dilation, threshold1 = 75, threshold2 = 200) # this doesn't work very well following dilation (for both original and resized)
    dilate_large = cv2.Canny(blurred, 0, CANNY, apertureSize=3)
    dilate_edged = cv2.Canny(
        dilation_small, threshold1=75, threshold2=200
    )  # this doesn't work very well following dilation (for both original and resized)
    bds_edged = cv2.Canny(bd_small, threshold1=75, threshold2=200)
    dsb_edged = cv2.Canny(dsb, threshold1=75, threshold2=200)
Esempio n. 4
0
                "--image",
                required=True,
                help="path to input image file")
args = vars(ap.parse_args())

image = cv2.imread(args["image"], 1)
orig = image.copy()

height, width = image.shape[:2]
new_width = 100.0
scaling_factor = new_width / width
# ratio = image.shape[0] / 500.0
# ratio = image.shape[1] / 100.0
# image = imutils.resize(image, height = 100)
ratio = 1 / scaling_factor
image = imutils.resize_new(image, scaling_factor=scaling_factor)
print ratio

# convert to grayscale and blur to smooth
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)

# blurred = cv2.copyMakeBorder(blurred, 5, 5, 5, 5, cv2.BORDER_CONSTANT, value=[0, 0, 0])		 # added this 11/2/17. Trying to work with document occlusion.

# apply Canny Edge Detection ....look into marheldritch
edged = cv2.Canny(
    blurred, threshold1=75,
    threshold2=200)  # was 0, 50...not sure what these numbers mean

closedEdges = cv2.morphologyEx(edged, cv2.MORPH_CLOSE, kernel=np.ones(
    (5, 11)))  # added this 11/2/17. Trying to work with document occlusion.