当前位置: 首页 > news >正文

c# 视觉识别图片文字 二维码

1.二维码识别  插件 ZXing.Net 
using System;
using System.Drawing; // 如果你使用的是System.Drawing.Common
using ZXing;class Program
{static void Main(){string imagePath = "path_to_your_qr_code_image.png";var barcodeBitmap = (Bitmap)Image.FromFile(imagePath);var barcodeReader = new BarcodeReader();var result = barcodeReader.Decode(barcodeBitmap);if (result != null){Console.WriteLine("二维码内容: " + result.Text);}else{Console.WriteLine("未能识别二维码内容");}}
}2.识别字符 插件:Tesseract
using System;
using System.Drawing;
using Tesseract;class Program
{static void Main(){string imagePath = "path_to_your_image.png";// 确保已下载并引用了 Tesseract 的语言数据文件(.traineddata)string tessdataPath = "path_to_tessdata"; // 通常包含 "eng.traineddata" 等文件using (var engine = new TesseractEngine(tessdataPath, "eng", EngineMode.Default)){using (var img = Pix.LoadFromFile(imagePath)){using (var page = engine.Process(img)){Console.WriteLine("识别结果: " + page.GetText());Console.WriteLine("置信度: " + page.GetMeanConfidence());}}}}
}

裁剪图片:

 public static void caijian(string inputPath, string outputPath,int x,int y,int width,int height){// 加载原始图片using (Bitmap originalBitmap = new Bitmap(inputPath)){// 定义裁剪区域(x, y, width, height)Rectangle cropArea = new Rectangle(x, y, width, height); // 修改这些值以适应你的需求// 创建裁剪后的图片using (Bitmap croppedBitmap = CropImage(originalBitmap, cropArea)){// 保存裁剪后的图片croppedBitmap.Save(outputPath);}}}static Bitmap CropImage(Bitmap source, Rectangle cropArea){// 确保裁剪区域在源图像范围内if (cropArea.X < 0 || cropArea.Y < 0 || cropArea.Right > source.Width || cropArea.Bottom > source.Height){throw new ArgumentException("裁剪区域超出了图像边界");}Bitmap croppedImage = new Bitmap(cropArea.Width, cropArea.Height);using (Graphics g = Graphics.FromImage(croppedImage)){g.DrawImage(source, new Rectangle(0, 0, cropArea.Width, cropArea.Height),cropArea, GraphicsUnit.Pixel);}return croppedImage;}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
using System.Drawing; // 如果你使用的是System.Drawing.Common
using ZXing;
using Tesseract;namespace ConsoleApp1
{class Program{static void Main(string[] args){string outimagePath1 = Environment.CurrentDirectory + "\\outLab.jpg";string outimagePath2 = Environment.CurrentDirectory + "\\outStart.jpg";string imagePath3 = Environment.CurrentDirectory + "\\333330.jpg";caijian(imagePath3, outimagePath1, 1600, 1250, 1500, 350);Getlab(outimagePath1);caijian(imagePath3, outimagePath2,475,873,738,673);GetChistring(outimagePath2);Console.Read();}public static void caijian(string inputPath, string outputPath,int x,int y,int width,int height){// 加载原始图片using (Bitmap originalBitmap = new Bitmap(inputPath)){// 定义裁剪区域(x, y, width, height)Rectangle cropArea = new Rectangle(x, y, width, height); // 修改这些值以适应你的需求// 创建裁剪后的图片using (Bitmap croppedBitmap = CropImage(originalBitmap, cropArea)){// 保存裁剪后的图片croppedBitmap.Save(outputPath);}}}static Bitmap CropImage(Bitmap source, Rectangle cropArea){// 确保裁剪区域在源图像范围内if (cropArea.X < 0 || cropArea.Y < 0 || cropArea.Right > source.Width || cropArea.Bottom > source.Height){throw new ArgumentException("裁剪区域超出了图像边界");}Bitmap croppedImage = new Bitmap(cropArea.Width, cropArea.Height);using (Graphics g = Graphics.FromImage(croppedImage)){g.DrawImage(source, new Rectangle(0, 0, cropArea.Width, cropArea.Height),cropArea, GraphicsUnit.Pixel);}return croppedImage;}public static void GetChistring(string imagePath){try{// 确保已下载并引用了 Tesseract 的语言数据文件(.traineddata)//var engine = new TesseractEngine(tessdataPath, "chi_sim", EngineMode.LstmOnly)string tessdataPath = Environment.CurrentDirectory+ "\\tessdata"; // 通常包含 "eng.traineddata" 等文件var engine = new TesseractEngine(tessdataPath, "chi_sim", EngineMode.Default | EngineMode.LstmOnly);var img = Pix.LoadFromFile(imagePath);var page = engine.Process(img);Console.WriteLine("识别结果: " + page.GetText());Console.WriteLine("置信度: " + page.GetMeanConfidence());}catch (Exception e){Console.WriteLine(e);}}public static void GetENstring(string imagePath){try{// 确保已下载并引用了 Tesseract 的语言数据文件(.traineddata)//var engine = new TesseractEngine(tessdataPath, "chi_sim", EngineMode.LstmOnly)string tessdataPath = Environment.CurrentDirectory + "\\tessdata"; // 通常包含 "eng.traineddata" 等文件var engine = new TesseractEngine(tessdataPath, "eng", EngineMode.Default | EngineMode.LstmOnly);var img = Pix.LoadFromFile(imagePath);var page = engine.Process(img);Console.WriteLine("识别结果: " + page.GetText());Console.WriteLine("置信度: " + page.GetMeanConfidence());}catch (Exception e){Console.WriteLine(e);}}public static void Getlab(string imagePath){var barcodeBitmap = (Bitmap)System.Drawing.Image.FromFile(imagePath);var barcodeReader = new BarcodeReader{Options = new ZXing.Common.DecodingOptions{// 支持多种条形码格式,包括二维码PossibleFormats = new List<BarcodeFormat>{BarcodeFormat.CODE_128, BarcodeFormat.CODE_39, BarcodeFormat.EAN_13,BarcodeFormat.EAN_8, BarcodeFormat.UPC_A, BarcodeFormat.UPC_E,BarcodeFormat.QR_CODE, BarcodeFormat.DATA_MATRIX}}};var result = barcodeReader.Decode(barcodeBitmap);if (result != null){Console.WriteLine("识别内容: " + result.Text);}else{Console.WriteLine("未能识别内容");}}}
}

 

 将图片用Windows画图打开确认像素点 和大小进行裁剪后交给算法识别;

GitCode - 全球开发者的开源社区,开源代码托管平台

下载训练模型:chi_sim.traineddata 中文

下载训练模型:eng.traineddata 英文

相关文章:

c# 视觉识别图片文字 二维码

1.二维码识别 插件 ZXing.Net using System; using System.Drawing; // 如果你使用的是System.Drawing.Common using ZXing;class Program {static void Main(){string imagePath "path_to_your_qr_code_image.png";var barcodeBitmap (Bitmap)Image.FromFile(im…...

UEFI——访问PCI/PCIE设备(二)

一、支持访问PCI/PCIE设备的Protocol UEFI中提供了两个主要的模块来支持PCI总线&#xff0c;一是PCI Host Bridge&#xff08;PCI主桥&#xff09;控制器驱动&#xff0c;另一个是PCI总线驱动。这两个模块是和特定的平台硬件绑定的&#xff0c;在这种机制下&#xff0c;屏蔽了…...

决策树算法的介绍与应用

目录 引言 决策树算法的基本原理 表格总结&#xff1a;决策树的构建步骤 决策树算法的 MATLAB 实现 示例&#xff1a;使用决策树进行分类预测 决策树的应用场景 表格总结&#xff1a;决策树的主要应用领域 决策树的优势与局限 结论 引言 决策树是一种广泛应用于数据挖掘…...

杰发科技Bootloader(3)—— 基于7801的APP切到Boot

为了方便在APP中跳转到Boot重新进行升级&#xff0c;有两种办法&#xff0c;7840同样可以使用。 1. 调用reset接口进行复位&#xff0c;复位后会先进Boot&#xff0c;再自动跳转到App。 NVIC_SystemReset(); 2. 直接使用跳转指令&#xff0c;参考Boot跳转到App代码&#xff0…...

Leetcode面试经典150题-138.随机链表的复制

题目比较简单&#xff0c;重点是理解思想&#xff0c;random不管&#xff0c;copy一定要放在next 而且里面的遍历过程不能省略 解法都在代码里&#xff0c;不懂就留言或者私信 /* // Definition for a Node. class Node {int val;Node next;Node random;public Node(int val…...

freemarker模板学习笔记

文章目录 freemarker常用指令if-elseif-else指令switch, case, default, break指令list, else, items, sep, break 指令<#list>指令语法<#else> 指令<#items> 指令<#sep> 指令<#break> 指令 include 指令<#include> 基础知识<#include&…...

高亚科技与广东海悟携手,打造全流程电子竞标管理平台!

近日&#xff0c;中国企业管理软件资深服务商高亚科技与广东海悟科技有限公司&#xff08;以下简称“海悟”&#xff09;正式签署合作协议&#xff0c;双方将基于高亚科技的8Manage SRM系统&#xff0c;推进海悟采购管理的数字化升级&#xff0c;实现全流程在线电子竞标管理&am…...

240908-结合DBGPT与Ollama实现RAG本地知识检索增强

A. 最终效果 B. 背景说明 DBGPT在0.5.6版本中开始支持Ollama&#xff1a;v0.5.6 版本更新 网友对其Web端及界面端的设置进行了分享&#xff1a; feat(model): support ollama as an optional llm & embedding proxy by GITHUBear Pull Request #1475 eosphoros-ai/DB-G…...

AMD ThinkSystem服务器上的 Linux 和 C 状态设置 - Lenovo ThinkSystem

受影响的配置 该系统可以是以下任何Lenovo服务器&#xff1a; ThinkSystem 、SR645&#xff08; ThinkSystem &#xff09;ThinkSystem &#xff0c;SR645 V3&#xff08; ThinkSystem &#xff09;ThinkSystem &#xff0c;SR635 V3&#xff08; ThinkSystem &#xff09;Th…...

Redis过期删除和缓存淘汰

1. 过期删除 在 Redis 中&#xff0c;键的过期删除机制主要包括惰性删除&#xff08;Lazy Deletion&#xff09;和定期删除&#xff08;Periodic Deletion&#xff09;。这两种策略有各自的优缺点&#xff0c;Redis 最终会结合这两种方法来管理过期键。 1.1 惰性删除&#xf…...

Golang | Leetcode Golang题解之第401题二进制手表

题目&#xff1a; 题解&#xff1a; func readBinaryWatch(turnedOn int) (ans []string) {for i : 0; i < 1024; i {h, m : i>>6, i&63 // 用位运算取出高 4 位和低 6 位if h < 12 && m < 60 && bits.OnesCount(uint(i)) turnedOn {ans …...

TON智能合约stdlib_ext库:扩展功能一览

TON&#xff08;TheOpenNetwork&#xff09;作为一个去中心化的区块链平台&#xff0c;其智能合约功能强大而灵活。在TON智能合约的开发过程中&#xff0c;stdlib.fc库提供了基础的功能支持。然而&#xff0c;对于一些高级或特定的需求&#xff0c;stdlib.fc可能无法满足。为此…...

LabVIEW开发FPGA方法与FIFO数据丢失处理

开发基于NI 7975R FPGA的系统涉及一系列流程&#xff0c;包括驱动安装、LabVIEW项目设置、开发调试、编译和与Windows系统的通信。重点在于FIFO的正确配置&#xff0c;避免数据丢失是关键环节之一&#xff0c;尤其是在使用高速数据流传输时。以下将详细介绍这些过程&#xff0c…...

Python中的内存池机制

在Python中&#xff0c;内存管理是一个复杂但至关重要的主题&#xff0c;它直接关系到程序的性能和稳定性。Python的内存管理机制包括对象的分配、追踪以及回收&#xff0c;其中内存池&#xff08;Memory Pool&#xff09;是这一机制中的一个重要组成部分。内存池机制通过预先分…...

智能家居系统(基于STM32F103C8T6标准库+FreeRTOS+Qt串口开发实现)

视频演示&#xff1a;基于STM32F103C8T6标准库FreeRTOSQt串口开发实现的智能家居项目_哔哩哔哩_bilibili 基于STM32F103C8T6标准库FreeRTOSQt串口开发实现的智能家居项目: https://pan.baidu.com/s/1f41gAfOOnlcQoKoMx3o84A?pwd6j2g 提取码: 6j2g 注&#xff1a;本项目为学习完…...

[数据集][目标检测]脊椎检测数据集VOC+YOLO格式1137张1类别

数据集格式&#xff1a;Pascal VOC格式YOLO格式(不包含分割路径的txt文件&#xff0c;仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数)&#xff1a;1137 标注数量(xml文件个数)&#xff1a;1137 标注数量(txt文件个数)&#xff1a;1137 标注…...

大受欢迎的游戏却又意外被作者下架的《Flappy Bird》将重返iPhone

据"Flappy Bird 基金会"官网称&#xff0c;标志性的侧卷轴滚动游戏《Flappy Bird》将很快回归 iPhone。《Flappy Bird》于 2013 年发布&#xff0c;很快就获得了数千万次下载。然而&#xff0c;这款游戏在2014 年突然从 App Store 下架&#xff0c;原因是其越南开发者…...

Flutter类

Dart中的对象都继承自 Object 类&#xff0c;单继承&#xff08;extend关键字&#xff09;。Dart与Java、kotlin不同的是其无public、private、protected修饰符&#xff0c;默认public &#xff0c;通过在属性名、方法名前加 _下划线 来定义是否私有。 实现一个简单的类 class…...

深入解析全连接层:PyTorch 中的 nn.Linear、nn.Parameter 及矩阵运算

文章目录 数学概念&#xff08;全连接层&#xff0c;线性层&#xff09;nn.Linear()nn.Parameter()Q1. 为什么 self.weight 的权重矩阵 shape 使用 ( out_features , in_features ) (\text{out\_features}, \text{in\_features}) (out_features,in_features)而不是 ( in_featur…...

缓存对象反序列化失败

未定义serialVersionUID&#xff0c;会自动生成序列化号 新增了属性&#xff0c;序列号就变了&#xff0c;导致缓存对象反序列化失败。 所有缓存对象必须指定序列化id&#xff01; 那我如何找到未添加字段前 对象的序列化号呢&#xff1f;默认的序列化号是如何生成的呢&#…...

【网络】每天掌握一个Linux命令 - iftop

在Linux系统中&#xff0c;iftop是网络管理的得力助手&#xff0c;能实时监控网络流量、连接情况等&#xff0c;帮助排查网络异常。接下来从多方面详细介绍它。 目录 【网络】每天掌握一个Linux命令 - iftop工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景…...

反向工程与模型迁移:打造未来商品详情API的可持续创新体系

在电商行业蓬勃发展的当下&#xff0c;商品详情API作为连接电商平台与开发者、商家及用户的关键纽带&#xff0c;其重要性日益凸显。传统商品详情API主要聚焦于商品基本信息&#xff08;如名称、价格、库存等&#xff09;的获取与展示&#xff0c;已难以满足市场对个性化、智能…...

【WiFi帧结构】

文章目录 帧结构MAC头部管理帧 帧结构 Wi-Fi的帧分为三部分组成&#xff1a;MAC头部frame bodyFCS&#xff0c;其中MAC是固定格式的&#xff0c;frame body是可变长度。 MAC头部有frame control&#xff0c;duration&#xff0c;address1&#xff0c;address2&#xff0c;addre…...

MFC内存泄露

1、泄露代码示例 void X::SetApplicationBtn() {CMFCRibbonApplicationButton* pBtn GetApplicationButton();// 获取 Ribbon Bar 指针// 创建自定义按钮CCustomRibbonAppButton* pCustomButton new CCustomRibbonAppButton();pCustomButton->SetImage(IDB_BITMAP_Jdp26)…...

对WWDC 2025 Keynote 内容的预测

借助我们以往对苹果公司发展路径的深入研究经验&#xff0c;以及大语言模型的分析能力&#xff0c;我们系统梳理了多年来苹果 WWDC 主题演讲的规律。在 WWDC 2025 即将揭幕之际&#xff0c;我们让 ChatGPT 对今年的 Keynote 内容进行了一个初步预测&#xff0c;聊作存档。等到明…...

cf2117E

原题链接&#xff1a;https://codeforces.com/contest/2117/problem/E 题目背景&#xff1a; 给定两个数组a,b&#xff0c;可以执行多次以下操作&#xff1a;选择 i (1 < i < n - 1)&#xff0c;并设置 或&#xff0c;也可以在执行上述操作前执行一次删除任意 和 。求…...

Cinnamon修改面板小工具图标

Cinnamon开始菜单-CSDN博客 设置模块都是做好的&#xff0c;比GNOME简单得多&#xff01; 在 applet.js 里增加 const Settings imports.ui.settings;this.settings new Settings.AppletSettings(this, HTYMenusonichy, instance_id); this.settings.bind(menu-icon, menu…...

鸿蒙DevEco Studio HarmonyOS 5跑酷小游戏实现指南

1. 项目概述 本跑酷小游戏基于鸿蒙HarmonyOS 5开发&#xff0c;使用DevEco Studio作为开发工具&#xff0c;采用Java语言实现&#xff0c;包含角色控制、障碍物生成和分数计算系统。 2. 项目结构 /src/main/java/com/example/runner/├── MainAbilitySlice.java // 主界…...

微软PowerBI考试 PL300-在 Power BI 中清理、转换和加载数据

微软PowerBI考试 PL300-在 Power BI 中清理、转换和加载数据 Power Query 具有大量专门帮助您清理和准备数据以供分析的功能。 您将了解如何简化复杂模型、更改数据类型、重命名对象和透视数据。 您还将了解如何分析列&#xff0c;以便知晓哪些列包含有价值的数据&#xff0c;…...

基于 TAPD 进行项目管理

起因 自己写了个小工具&#xff0c;仓库用的Github。之前在用markdown进行需求管理&#xff0c;现在随着功能的增加&#xff0c;感觉有点难以管理了&#xff0c;所以用TAPD这个工具进行需求、Bug管理。 操作流程 注册 TAPD&#xff0c;需要提供一个企业名新建一个项目&#…...