首先下载PaddleOCR2.6如下包
using OpenCvSharp;
using Sdcb.PaddleInference;
using Sdcb.PaddleOCR;
using Sdcb.PaddleOCR.Models;
using Sdcb.PaddleOCR.Models.LocalV3;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WinFormsApp17
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
PaddleOcrAll all;
private void Form1_Load(object sender, EventArgs e)
{
FullOcrModel model = LocalFullModels.ChineseV3;
all = new PaddleOcrAll(model, PaddleDevice.Gpu())
{
AllowRotateDetection = true, /* 允许识别有角度的文字 */
Enable180Classification = false, /* 允许识别旋转角度大于90度的文字 */
};
}
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
for (int i = 0; i < 10; i++)
{
Stopwatch stp = new Stopwatch();
stp.Start();
byte[] sampleImageData = File.ReadAllBytes(@"C:\Users\xuc\Desktop\lite_demo.png");
using (Mat src = Cv2.ImDecode(sampleImageData, ImreadModes.Color))
{
PaddleOcrResult result = all.Run(src);
stp.Stop();
richTextBox1.AppendText("Total: " + stp.ElapsedMilliseconds + "ms\r\n");
foreach (PaddleOcrResultRegion region in result.Regions)
{
richTextBox1.AppendText(region.Text + "\r\n");
// richTextBox1.AppendText($"Text: {region.Text}, Score: {region.Score}, RectCenter: {region.Rect.Center}, RectSize: {region.Rect.Size}, Angle: {region.Rect.Angle}" + "\r\n");
}
}
}
}
}
}
GPU大概140ms,CPU大概400ms。分辨率400*300,
RTX2060,i5 10400,cuda11.6,cudnn8.4。
tensorrt没调通,包不太对,命令行也没报警,要么没输出,感觉应该能比gpu快一半。
------------------------------------------
试了一下编译原生c++的代码,GPU 230ms,TensorRT8.4 166ms。没有这个包快,不知道哪里不对。c和c++应该差不了这么多。