摘要:max_image = Mat.Zeros(new OpenCvSharp.Size(max_image_length, max_image_length), MatType.CV_8UC3);
百度网盘AI大赛-表格检测的第2名方案。
该算法包含表格边界框检测、表格分割和表格方向识别三个部分,首先,ppyoloe-plus-x 对边界框进行预测,并对置信度较高的表格边界框(box)进行裁剪。裁剪后的单个表格实例会送入到DBNet中进行语义分割,分割结果通过opencv轮廓处理获得表格关键点(point)。之后,我们根据DBNet计算的关键点在裁剪后的单个表格实例上绘制表格边界。最后,PP-LCNet结合表格边界先验和表格实例图像,对表格的方向进行预测,并根据之前定义的几何轮廓点与语义轮廓点的对应关系,将几何轮廓点映射为语义轮廓点。
本文使用C# OpenCvSharp DNN 实现百度网盘AI大赛-表格检测第2名方案第三部分-表格方向识别。
C# OpenCvSharp DNN 实现百度网盘AI大赛-表格检测第2名方案第一部分-表格边界框检测
C# OnnxRuntime 实现百度网盘AI大赛-表格检测第2名方案第二部分-表格分割
Model PropertiesInputs
name:input
tensor:Float[-1, 3, 624, 624]
Outputs
name:linear_1.tmp_1
tensor:Float[-1, 4]
using OpenCvSharp;
using OpenCvSharp.Dnn;
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace OpenCvSharp_DNN_Demo
{
public partial class frmMain : Form
{
publicfrmMain
{
InitializeComponent;
}
string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
string image_path = "";
string startupPath;
string classer_path;
DateTime dt1 = DateTime.Now;
DateTime dt2 = DateTime.Now;
string model_path;
Mat image;
Mat result_mat;
Mat result_image;
Mat result_mat_to_float;
Net opencv_net;
Mat BN_image;
float result_array;
int max_image_length;
Mat max_image;
Rect roi;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog;
ofd.Filter = fileFilter;
if(ofd.ShowDialog != DialogResult.OK)return;
pictureBox1.Image = ;
pictureBox2.Image = ;
textBox1.Text = "";
image_path = ofd.FileName;
pictureBox1.Image = new Bitmap(image_path);
image = new Mat(image_path);
}
private void Form1_Load(object sender, EventArgs e)
{
string model_path = "model/paddle_cls.onnx";
opencv_net = CvDnn.ReadNetFromOnnx(model_path);
image_path = "test_img/1.jpg";
}
private unsafe void button2_Click(object sender, EventArgs e)
{
if(image_path == "")
{
return;
}
if(image_path == "")
{
return;
}
textBox1.Text = "检测中,请稍等……";
Application.DoEvents;
Mat image = new Mat(image_path);
//缩放图片
max_image_length = image.Cols > image.Rows ? image.Cols : image.Rows;
max_image = Mat.Zeros(new OpenCvSharp.Size(max_image_length, max_image_length), MatType.CV_8UC3);
roi = new Rect(0, 0, image.Cols, image.Rows);
image.CopyTo(new Mat(max_image, roi));
//数据归一化处理
BN_image = CvDnn.BlobFromImage(max_image, 1 / 255.0, new OpenCvSharp.Size(624, 624), new Scalar(0, 0, 0),truefalse);
//配置图片输入数据
opencv_net.SetInput(BN_image);
dt1 = DateTime.Now;
//模型推理,读取推理结果
result_mat = opencv_net.Forward;
dt2 = DateTime.Now;
//将推理结果转为float数据类型
result_mat_to_float = new Mat(1, 4, MatType.CV_32F, result_mat.Data);
//将数据读取到数组中
result_mat_to_float.GetArrayfloat>(out result_array);
floatmax = result_array.Max; //
int maxIndex = Array.IndexOf(result_array, max); // 获取最大值的索引位置
//语义左上角位于几何左上角,定义为0;
//语义左上角位于几何右上角,定义为1;
//语义左上角位于几何右下角,定义了2;
//语义左上角位于几何左下角,定义为3。
textBox1.Text = "推理耗时:" + (dt2 - dt1).TotalMilliseconds + "ms\r\n";
string msg = "";
if(maxIndex == 0) {
msg = "语义左上角位于几何左上角";
}
elseif(maxIndex == 1)
{
msg = "语义左上角位于几何右上角";
}
elseif(maxIndex == 2)
{
msg = "语义左上角位于几何右下角";
}
elseif(maxIndex == 3)
{
msg = "语义左上角位于几何左下角";
}
textBox1.Text += "\r\n" + msg;
}
private void pictureBox2_DoubleClick(object sender, EventArgs e)
{
Common.ShowNormalImg(pictureBox2.Image);
}
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
Common.ShowNormalImg(pictureBox1.Image);
}
}
}
https://aistudio.baidu.com/projectdetail/5398861?searchKeyword=表格检测大赛&searchTab=ALL
来源:opendotnet
免责声明:本站系转载,并不代表本网赞同其观点和对其真实性负责。如涉及作品内容、版权和其它问题,请在30日内与本站联系,我们将在第一时间删除内容!