白嫖微信OCR,实现提取图片中的文字(c#版本)

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;

[Nullable(0), NullableContext(1)]
internal class Program
{
	[NullableContext(0)]
	public delegate void SetResultDelegate(IntPtr result);

	[Nullable(0)]
	public class StringResult
	{
		public string result_ = "";

		public void SetResult(IntPtr dt)
		{
			int num = 0;
			while (Marshal.ReadByte(dt, num) != 0)
			{
				num++;
			}
			byte[] array = new byte[num];
			Marshal.Copy(dt, array, 0, num);
			this.result_ = Encoding.get_UTF8().GetString(array);
		}

		public string GetResult()
		{
			return this.result_;
		}
	}

	[DllImport("wcocr.dll", CallingConvention = CallingConvention.Cdecl)]
	public static extern bool wechat_ocr([MarshalAs(21)] string ocr_exe, [MarshalAs(21)] string wechat_dir, [MarshalAs(20)] string imgfn, Program.SetResultDelegate set_res);

	[DllImport("wcocr.dll", CallingConvention = CallingConvention.Cdecl)]
	public static extern void stop_ocr();

	private static void Main(string[] args)
	{
		if (args.Length != 3)
		{
			Console.WriteLine("Usage: wcocr.exe ocr_exe wechat_dir imgfn");
			return;
		}
		Program.StringResult stringResult = new Program.StringResult();
		Program.SetResultDelegate set_res = new Program.SetResultDelegate(stringResult.SetResult);
		bool flag = Program.wechat_ocr(args[0], args[1], args[2], set_res);
		DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(18, 2);
		defaultInterpolatedStringHandler.AppendLiteral("OCR Success: ");
		defaultInterpolatedStringHandler.AppendFormatted<bool>(flag);
		defaultInterpolatedStringHandler.AppendLiteral(" res:");
		defaultInterpolatedStringHandler.AppendFormatted(stringResult.GetResult());
		Console.WriteLine(defaultInterpolatedStringHandler.ToStringAndClear());
		Program.stop_ocr();
	}
}

原文
GitHub - swigger/wechat-ocr
整理资料
https://download.youkuaiyun.com/download/qq_36664772/90776859

如有侵权联系删除 , C# Net WeChatOCR.rar c# 调用微信ocr 识别 调用方式 cmd:ConsoleApp2.exe test.png
注意:进过测试,win7电脑正常用 w10部分电脑会卡死 部分win10能正常用
用之前要测试是否断网可用

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序007

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值