linux百度文字识别,C#通过百度Ai接口实现图片文字识别核心代码

亲爱的:若该文章解决了您的问题,可否收藏+评论+分享呢?

相关介绍及图片展示以及下载地址请参考文章:http://blog.tag.gg/518.html  以下是核心代码,直接复制到您的项目中可以直接使用,若转载请注明出处啊,码字很辛苦啊,

核心代码已足够你使用,若需要完整代码,请在评论中留下您的邮箱,

选择图片及上传按钮代码如下:

private void button1_Click (object sender, EventArgs e) {

try {

richTextBox1.Text = "";

Openimgfile (); //调用文件打开对话框

this.button1.Text = "上传并提取中...";

pictureBox1.LoadAsync (textBox1.Text);

GeneralBasicDemo ();

调用百度ai接口

} catch (Exception ex) {

MessageBox.Show ("报错,原因:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);

}

}

4affd6f794c749a2a5a37b5dfe9aca27.png

打开文件对话框过程代码:

//打开文件模块

public void Openimgfile () {

try {

OpenFileDialog dialog = new OpenFileDialog ();

dialog.Filter = "图片(*.png;*.jpg;*.bmp;*.jpeg)|*.png;*.jpg;*.bmp;*.jpeg";

if (dialog.ShowDialog () == DialogResult.OK) {

this.textBox1.Text = dialog.FileName;

}

} catch (Exception ex) {

MessageBox.Show ("报错,原因:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);

}

}

9bb1792c29ca8327f2a3b53f563798ca.png

调用百度api接口 过程代码:

public void GeneralBasicDemo () {

try {

string Json;

var APP_ID = "123456";

var API_KEY = "123456";

var SECRET_KEY = "123456";

var client = new Baidu.Aip.Ocr.Ocr (API_KEY, SECRET_KEY);

client.Timeout = 60000;

var image = File.ReadAllBytes (textBox1.Text);

var result = client.GeneralBasic (image);

Console.WriteLine (result);

// 如果有可选参数

var options = new Dictionary { { "language_type", "CHN_ENG" },

{ "detect_direction", "true" },

{ "detect_language", "true" },

{ "probability", "true" }

};

result = client.GeneralBasic (image, options);

//Console.WriteLine(result);

//richTextBox1.Text = result.ToString();

Json = result.ToString ();

Json_get (Json);

this.button1.Text = "选择图片并提取文字";

} catch (Exception ex) {

MessageBox.Show ("报错,原因:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);

this.button1.Text = "选择图片并提取文字";

}

}

1455061ac50030e6a23e1ca90deb5681.png

百度返回的内容是json格式,需要从json中提取words关键字对应的值, 若需要,请留言,我单独发邮箱

以上是核心代码,可以直接复制到你工程中使用,码字很辛苦啊,转载注明出处啊,

亲爱的:若该文章解决了您的问题,可否收藏+评论+分享呢?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值