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总线,一是PCI Host Bridge(PCI主桥)控制器驱动,另一个是PCI总线驱动。这两个模块是和特定的平台硬件绑定的,在这种机制下,屏蔽了…...
决策树算法的介绍与应用
目录 引言 决策树算法的基本原理 表格总结:决策树的构建步骤 决策树算法的 MATLAB 实现 示例:使用决策树进行分类预测 决策树的应用场景 表格总结:决策树的主要应用领域 决策树的优势与局限 结论 引言 决策树是一种广泛应用于数据挖掘…...
杰发科技Bootloader(3)—— 基于7801的APP切到Boot
为了方便在APP中跳转到Boot重新进行升级,有两种办法,7840同样可以使用。 1. 调用reset接口进行复位,复位后会先进Boot,再自动跳转到App。 NVIC_SystemReset(); 2. 直接使用跳转指令,参考Boot跳转到App代码࿰…...
Leetcode面试经典150题-138.随机链表的复制
题目比较简单,重点是理解思想,random不管,copy一定要放在next 而且里面的遍历过程不能省略 解法都在代码里,不懂就留言或者私信 /* // 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&…...
高亚科技与广东海悟携手,打造全流程电子竞标管理平台!
近日,中国企业管理软件资深服务商高亚科技与广东海悟科技有限公司(以下简称“海悟”)正式签署合作协议,双方将基于高亚科技的8Manage SRM系统,推进海悟采购管理的数字化升级,实现全流程在线电子竞标管理&am…...
240908-结合DBGPT与Ollama实现RAG本地知识检索增强
A. 最终效果 B. 背景说明 DBGPT在0.5.6版本中开始支持Ollama:v0.5.6 版本更新 网友对其Web端及界面端的设置进行了分享: 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服务器: ThinkSystem 、SR645( ThinkSystem )ThinkSystem ,SR645 V3( ThinkSystem )ThinkSystem ,SR635 V3( ThinkSystem )Th…...
Redis过期删除和缓存淘汰
1. 过期删除 在 Redis 中,键的过期删除机制主要包括惰性删除(Lazy Deletion)和定期删除(Periodic Deletion)。这两种策略有各自的优缺点,Redis 最终会结合这两种方法来管理过期键。 1.1 惰性删除…...
Golang | Leetcode Golang题解之第401题二进制手表
题目: 题解: 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(TheOpenNetwork)作为一个去中心化的区块链平台,其智能合约功能强大而灵活。在TON智能合约的开发过程中,stdlib.fc库提供了基础的功能支持。然而,对于一些高级或特定的需求,stdlib.fc可能无法满足。为此…...
LabVIEW开发FPGA方法与FIFO数据丢失处理
开发基于NI 7975R FPGA的系统涉及一系列流程,包括驱动安装、LabVIEW项目设置、开发调试、编译和与Windows系统的通信。重点在于FIFO的正确配置,避免数据丢失是关键环节之一,尤其是在使用高速数据流传输时。以下将详细介绍这些过程,…...
Python中的内存池机制
在Python中,内存管理是一个复杂但至关重要的主题,它直接关系到程序的性能和稳定性。Python的内存管理机制包括对象的分配、追踪以及回收,其中内存池(Memory Pool)是这一机制中的一个重要组成部分。内存池机制通过预先分…...
智能家居系统(基于STM32F103C8T6标准库+FreeRTOS+Qt串口开发实现)
视频演示:基于STM32F103C8T6标准库FreeRTOSQt串口开发实现的智能家居项目_哔哩哔哩_bilibili 基于STM32F103C8T6标准库FreeRTOSQt串口开发实现的智能家居项目: https://pan.baidu.com/s/1f41gAfOOnlcQoKoMx3o84A?pwd6j2g 提取码: 6j2g 注:本项目为学习完…...
[数据集][目标检测]脊椎检测数据集VOC+YOLO格式1137张1类别
数据集格式:Pascal VOC格式YOLO格式(不包含分割路径的txt文件,仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数):1137 标注数量(xml文件个数):1137 标注数量(txt文件个数):1137 标注…...
大受欢迎的游戏却又意外被作者下架的《Flappy Bird》将重返iPhone
据"Flappy Bird 基金会"官网称,标志性的侧卷轴滚动游戏《Flappy Bird》将很快回归 iPhone。《Flappy Bird》于 2013 年发布,很快就获得了数千万次下载。然而,这款游戏在2014 年突然从 App Store 下架,原因是其越南开发者…...
Flutter类
Dart中的对象都继承自 Object 类,单继承(extend关键字)。Dart与Java、kotlin不同的是其无public、private、protected修饰符,默认public ,通过在属性名、方法名前加 _下划线 来定义是否私有。 实现一个简单的类 class…...
深入解析全连接层:PyTorch 中的 nn.Linear、nn.Parameter 及矩阵运算
文章目录 数学概念(全连接层,线性层)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,会自动生成序列化号 新增了属性,序列号就变了,导致缓存对象反序列化失败。 所有缓存对象必须指定序列化id! 那我如何找到未添加字段前 对象的序列化号呢?默认的序列化号是如何生成的呢&#…...
【大模型RAG】拍照搜题技术架构速览:三层管道、两级检索、兜底大模型
摘要 拍照搜题系统采用“三层管道(多模态 OCR → 语义检索 → 答案渲染)、两级检索(倒排 BM25 向量 HNSW)并以大语言模型兜底”的整体框架: 多模态 OCR 层 将题目图片经过超分、去噪、倾斜校正后,分别用…...
工业安全零事故的智能守护者:一体化AI智能安防平台
前言: 通过AI视觉技术,为船厂提供全面的安全监控解决方案,涵盖交通违规检测、起重机轨道安全、非法入侵检测、盗窃防范、安全规范执行监控等多个方面,能够实现对应负责人反馈机制,并最终实现数据的统计报表。提升船厂…...
(二)TensorRT-LLM | 模型导出(v0.20.0rc3)
0. 概述 上一节 对安装和使用有个基本介绍。根据这个 issue 的描述,后续 TensorRT-LLM 团队可能更专注于更新和维护 pytorch backend。但 tensorrt backend 作为先前一直开发的工作,其中包含了大量可以学习的地方。本文主要看看它导出模型的部分&#x…...
《用户共鸣指数(E)驱动品牌大模型种草:如何抢占大模型搜索结果情感高地》
在注意力分散、内容高度同质化的时代,情感连接已成为品牌破圈的关键通道。我们在服务大量品牌客户的过程中发现,消费者对内容的“有感”程度,正日益成为影响品牌传播效率与转化率的核心变量。在生成式AI驱动的内容生成与推荐环境中࿰…...
跨链模式:多链互操作架构与性能扩展方案
跨链模式:多链互操作架构与性能扩展方案 ——构建下一代区块链互联网的技术基石 一、跨链架构的核心范式演进 1. 分层协议栈:模块化解耦设计 现代跨链系统采用分层协议栈实现灵活扩展(H2Cross架构): 适配层…...
解决本地部署 SmolVLM2 大语言模型运行 flash-attn 报错
出现的问题 安装 flash-attn 会一直卡在 build 那一步或者运行报错 解决办法 是因为你安装的 flash-attn 版本没有对应上,所以报错,到 https://github.com/Dao-AILab/flash-attention/releases 下载对应版本,cu、torch、cp 的版本一定要对…...
SpringTask-03.入门案例
一.入门案例 启动类: package com.sky;import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCach…...
在WSL2的Ubuntu镜像中安装Docker
Docker官网链接: https://docs.docker.com/engine/install/ubuntu/ 1、运行以下命令卸载所有冲突的软件包: for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done2、设置Docker…...
MySQL账号权限管理指南:安全创建账户与精细授权技巧
在MySQL数据库管理中,合理创建用户账号并分配精确权限是保障数据安全的核心环节。直接使用root账号进行所有操作不仅危险且难以审计操作行为。今天我们来全面解析MySQL账号创建与权限分配的专业方法。 一、为何需要创建独立账号? 最小权限原则…...
视频行为标注工具BehaviLabel(源码+使用介绍+Windows.Exe版本)
前言: 最近在做行为检测相关的模型,用的是时空图卷积网络(STGCN),但原有kinetic-400数据集数据质量较低,需要进行细粒度的标注,同时粗略搜了下已有开源工具基本都集中于图像分割这块,…...
