ocrolib_ext.py 文件源码

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

项目:deep_ocr 作者: JinpengLI 项目源码 文件源码
def compute_colseps_conv(binary, csminheight, maxcolseps, scale=1.0, debug=False):
    """Find column separators by convoluation and
    thresholding."""
    h,w = binary.shape
    # find vertical whitespace by thresholding
    smoothed = gaussian_filter(1.0 * binary, (scale, scale*0.5))
    smoothed = uniform_filter(smoothed, (5.0*scale,1))
    thresh = (smoothed<np.amax(smoothed)*0.1)
    if debug:
        debug_show(thresh, "compute_colseps_conv thresh")
    # find column edges by filtering
    grad = gaussian_filter(1.0*binary, (scale, scale*0.5), order=(0,1))
    grad = uniform_filter(grad, (10.0*scale,1))
    # grad = abs(grad) # use this for finding both edges
    grad = (grad>0.5*np.amax(grad))
    if debug:
        debug_show(grad, "compute_colseps_conv grad")
    # combine edges and whitespace
    seps = np.minimum(thresh,maximum_filter(grad, (int(scale), int(5*scale))))
    seps = maximum_filter(seps,(int(2*scale),1))
    if debug:
        debug_show(seps, "compute_colseps_conv seps")
    # select only the biggest column separators
    seps = morph.select_regions(seps,sl.dim0,
                                min=csminheight*scale,
                                nbest=maxcolseps)
    if debug:
        debug_show(seps, "compute_colseps_conv 4seps")
    return seps
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号