【算法介绍】
让我们开始讨论Deskeweing算法的一般概念。我们的主要目标是将旋转的图像分成文本块,并确定它们的角度。为了让您详细了解我将使用的方法:
【效果展示】
【实现部分代码】
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FIRC
{
public partial class Form1 : Form
{
Bitmap src = null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "图文件(*.*)|*.jpg;*.png;*.jpeg;*.bmp";
openFileDialog.RestoreDirectory = true;
openFileDialog.Multiselect = false;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
src = new Bitmap(openFileDialog.FileName);
pictureBox1.Image = src;
}
}
private void button2_Click(object sender, EventArgs e)
{
if(pictureBox1.Image==null)
{
return;
}
Stopwatch sw = new Stopwatch();
sw.Start();
var gd = new gmseDeskew(src);
var angle = gd.GetSkewAngle();
var resultImage = gmseDeskew.RotateImage(src, angle);
sw.Stop();
this.Text = "耗时" + sw.Elapsed.TotalSeconds + "秒";
pictureBox2.Image = resultImage;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btn_video_Click(object sender, EventArgs e)
{
}
}
}
【视频演示】
bilibili.com/video/BV1x94y1g7uT
【源码下载】
【测试环境】
VS2019
netframework4.7.2(支持netframwork2.0以上都可以)
【参考文献】
[1]?guanshanw.com/post/30887.html