def find_number_contours(the_image):
    # cv2_helper.Image.show(the_image)
    ''' This blur operation is quite useful '''
    the_image = cv2.GaussianBlur(the_image,ksize=(5,5), sigmaX=0)

    ''' open, it could remove the border '''
    kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
    the_image = cv2.morphologyEx(the_image, cv2.MORPH_OPEN, kernel)
    # the_image = cv2.erode(the_image, kernel)
    # cv2_helper.Image.show(the_image)
    # the_image = cv2.adaptiveThreshold(the_image,WHITE,
    #     cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY_INV, blockSize=7, C=2)


    low_threshold, high_threshold = 40, 80

    the_image = cv2.Canny(the_image, low_threshold, high_threshold)

    ''' change the image to uint8'''
    the_image = cv2.convertScaleAbs(the_image)

    contours = cv2_helper.find_contours(the_image, None, 0.01)
    cv2_helper.Image.show_contours_with_color(the_image, contours)
    contours = filter(lambda c: filter_number_contour(c, the_image), contours)
    return contours
def find_max_contour(threshed_image, filter_func = None, accuracy_percent_with_perimeter=0.0001):
    contours = cv2_helper.find_contours(
        threshed_image, filter_func, accuracy_percent_with_perimeter)
    if len(contours) == 0:
        return None
    contour_area_arr = [cv2.contourArea(i) for i in contours]
    max_contour = contours[contour_area_arr.index(max(contour_area_arr))]
    return max_contour
示例#3
0
def find_max_square(threshed_pic_array):
    # squares = threshed_pic_array
    squares = cv2_helper.find_contours(threshed_pic_array, is_almost_square)
    square_perimeter_arr = [cv2.arcLength(i,True) for i in squares]
    return squares[square_perimeter_arr.index(max(square_perimeter_arr))]