Python Python plot 绘图

sunny0330 · September 16, 2019 · Last by sunny0330 replied at September 29, 2019 · 1463 hits


从原图中识别出轮廓,画出的图,
接下来想做文字识别,但是图片的线不够直,想知道有没有什么方法可以把线画直一点

源码如下:

def find_character_and_Keep(imgpath):
    from PIL import Image
    img = Image.open(imgpath).convert('L')
    img_arr = np.array(img)
    # print(img_arr)
    # saveImageTxtRR(img_arr, "gray")

    #二值图
    threshold = 245
    table = []
    for i in range(256):
        if i < threshold:
            table.append(1)
        else:
            table.append(0)

    photo = img.point(table, "1")
    #检测所有图形的轮廓
    contours = measure.find_contours(photo, 0.5)

    #绘制轮廓
    fig, axes = plt.subplots(1, 2, figsize=(8, 8))#一行两列
    ax0, ax1 = axes.ravel()
    ax0.imshow(photo, plt.cm.gray)
    ax0.set_title('original image')

    rows, cols = img.size
    ax1.axis([0, rows, cols, 0])
    for n, contour in enumerate(contours):
        if len(contour) < 300:
            figure = ax1.plot(contour[:, 1], contour[:, 0], linewidth=2, color='black', antialiased=True)

    ax1.axis('image')#适应图片大小
    ax1.set_title('contours')
    plt.show()
if __name__ =="__main__":
    imgpath = r"F:\learning\picture\code\data\default\volte_dial_button.png"
    find_character_and_Keep(imgpath)
最佳回复
共收到 7 条回复 时间 点赞

请各位大佬给建议

文字识别?是要 ocr 的效果吗?

滤波试一下
直接 OCR 不行吗

是的,OCR 结果,是 VELTE 识别不稳定

我之前也考虑的是卡锯齿,但是后面发现,生成图片默认的就是抗锯齿,

arrow 回复

直接 OCR 就是识别出来的字符特别不靠谱,VELTE,有时候又识别成 VOL(E,有建议吗

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up