zl程序教程

您现在的位置是:首页 >  云平台

当前栏目

DL之CNN:基于CRNN_OCR算法(keras,CNN+RNN)利用数据集(torch,mdb格式)训练来实现新图片上不定长度字符串进行识别—预测过程

识别训练算法数据 实现 基于 利用 字符串
2023-09-14 09:04:44 时间

DL之CNN:基于CRNN_OCR算法(keras,CNN+RNN)利用数据集(torch,mdb格式)训练来实现新图片上不定长度字符串进行识别—预测过程

 

目录

输出结果

设计思路

核心代码


 

 

 

输出结果

1、五张图片进行测试,并输出测试结果




输出结果分别为



 


结论,前两张图片的测试效果,还是可以接受的。

 

设计思路

后期更新……

 

核心代码

后期更新……

def ocr_predict(im):  

    im = im.convert('L')           。
    scale = im.size[1]*1.0 / 32
    w = im.size[0] / scale
    w = int(w)
    im = im.resize((w,32))         
    img = np.array(im).astype(np.float32)/255.0    
#     print(img)
    X  = img.reshape((32,w,1))      
    X = np.array([X])
    y_pred = basemodel.predict(X)     
#     out01    = decode(y_pred)  
#     print('out01的输出:',out01)
    y_pred = y_pred[:,2:,:]     
     
    out    = decode(y_pred)           
#     print('out01过滤后的输出:',out)
    #out = K.get_value(K.ctc_decode(y_pred, input_length=np.ones(y_pred.shape[0])*y_pred.shape[1], )[0][0])[:, :]
    
    #out = u''.join([characters[x] for x in out[0]])
    
    if len(out)>0:                 
        while out[0]==u'。':                  
#             print('【out[0]==u。后输出】:', out)
            if len(out)>1:                       
               out = out[1:]
#                print('【out[1:]输出】:', out)
            else:                                
                break

    return out            #返回out




img = cv2.imread('./img/12.jpg')       
 
image = Image.fromarray(img).convert('L')   
print(sim_pred)