preprocess.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:neith 作者: Rabrg 项目源码 文件源码
def extract_chars(pixels):
    # use sci-kit image to find the contours of the image
    contours = measure.find_contours(pixels, CONTOUR_LEVEL)
    # calls an algorithm on the contours to remove unwanted overlapping contours like the holes in 6's, 8's, and 9's
    contours = __remove_overlap_contours(contours)

    # populate a dictionary with key of the left most x coordinate of the contour and value of the resized contour
    resized_char_dict = dict()
    for n, contour in enumerate(contours):
        min, max = __get_min_max(contour)
        resized_contour = transform.resize(pixels[int(min[0]):int(max[0]), int(min[1]):int(max[1])], (32, 32))
        resized_char_dict[min[1]] = resized_contour

    # sort the map by key (left most x coordinate of the contour)
    sorted_dict = sorted(resized_char_dict.items(), key=operator.itemgetter(0))
    # extract the contours from the sorted dictionary into a list
    extracted_chars = np.asarray([i[1] for i in sorted_dict])
    # normalize the contours by subtracting 0.5 to each pixel value
    np.subtract(extracted_chars, 0.5, out=extracted_chars)
    return extracted_chars
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号