def table_line(img, size=(512, 512), hprob=0.5, vprob=0.5, row=50, col=30, alph=15): sizew, sizeh = size inputBlob, fx, fy = letterbox_image(img[..., ::-1], (sizew, sizeh)) pred = model.predict(np.array([np.array(inputBlob) / 255.0])) pred = pred[0] vpred = pred[..., 1] > vprob ##竖线 hpred = pred[..., 0] > hprob ##横线 vpred = vpred.astype(int) hpred = hpred.astype(int) colboxes = get_table_line(vpred, axis=1, lineW=col) rowboxes = get_table_line(hpred, axis=0, lineW=row) ccolbox = [] crowlbox = [] if len(rowboxes) > 0: rowboxes = np.array(rowboxes) rowboxes[:, [0, 2]] = rowboxes[:, [0, 2]] / fx rowboxes[:, [1, 3]] = rowboxes[:, [1, 3]] / fy xmin = rowboxes[:, [0, 2]].min() xmax = rowboxes[:, [0, 2]].max() ymin = rowboxes[:, [1, 3]].min() ymax = rowboxes[:, [1, 3]].max() ccolbox = [[xmin, ymin, xmin, ymax], [xmax, ymin, xmax, ymax]] rowboxes = rowboxes.tolist() if len(colboxes) > 0: colboxes = np.array(colboxes) colboxes[:, [0, 2]] = colboxes[:, [0, 2]] / fx colboxes[:, [1, 3]] = colboxes[:, [1, 3]] / fy xmin = colboxes[:, [0, 2]].min() xmax = colboxes[:, [0, 2]].max() ymin = colboxes[:, [1, 3]].min() ymax = colboxes[:, [1, 3]].max() colboxes = colboxes.tolist() crowlbox = [[xmin, ymin, xmax, ymin], [xmin, ymax, xmax, ymax]] rowboxes += crowlbox colboxes += ccolbox rboxes_row_, rboxes_col_ = adjust_lines(rowboxes, colboxes, alph=alph) rowboxes += rboxes_row_ colboxes += rboxes_col_ nrow = len(rowboxes) ncol = len(colboxes) for i in range(nrow): for j in range(ncol): rowboxes[i] = line_to_line(rowboxes[i], colboxes[j], 10) colboxes[j] = line_to_line(colboxes[j], rowboxes[i], 10) return rowboxes, colboxes
时间: 2024-04-27 11:25:41 浏览: 107
H616关闭cec dts文件hdmi_cec_support = 0
5星 · 资源好评率100%
这段代码是用于检测表格线的函数。输入参数包括原始图像、目标尺寸、水平/竖直表格线的概率、期望的行数和列数以及表格线的角度参数。函数利用深度学习模型对输入图像进行预测,得到竖线和横线的二值预测图。接着,函数将预测结果进行后处理,得到表格线的位置信息。具体来说,函数调用了 get_table_line 函数对二值预测图进行处理,得到横线和竖线的坐标信息。然后,函数对坐标信息进行调整,得到更加精确的表格线位置信息。最后,函数将横线和竖线的位置信息合并成表格线的位置信息返回。
阅读全文