C# Winform+Halcon結合標準視覺工具

介紹+

winform與halcon結合標準化工具實例

軟件架構

軟件架構說明 基于NET6 WINFORM+HALCON

實現標準化視覺檢測工具

集成相機通訊

集成PLC通訊

TCP等常見通訊

支持常見halcon算子

  • 圖形采集
  • blob分析
  • 高精度匹配
  • 顏色提取
  • 找幾何體
  • 二維碼提取
  • OCR識別
  • 等等?

輸入圖片說明

?。。。?

輸入圖片說明

安裝教程

https://dotnet.microsoft.com/zh-cn/download/dotnet/6.0

使用說明

安裝 NET6 SDK,編譯即可運行

對入門的同學應該有較好的學習意義

本項目涵蓋了標準化視覺檢測工具的大部分功能,有興趣的小伙伴可以請我吃一頓肯德基,獲取源碼進行學習。

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using HalconDotNet;
using MT_OCR5._0;
using PaddleOCRSharp;

namespace Vision.Winform.Algorithm
{ ? //識別各種二維碼,一維碼, 字符識別

? ? namespace MT_code
? ? {
? ? ? ? public class QR
? ? ? ? {
? ? ? ? ? ? public ToolPar toolPar = new ToolPar();
? ? ? ? ? ? public bool status = true;
? ? ? ? ? ? internal HObject image = null;

? ? ? ? ? ? //二維碼識別句柄
? ? ? ? ? ? internal HTuple modelID = null;

? ? ? ? ? ? public string CodeType = "QR Code";
? ? ? ? ? ? public string ParamName = "default_parameters";
? ? ? ? ? ? public string ParamValue = "standard_recognition";

? ? ? ? ? ? private void creathandle()
? ? ? ? ? ? {
? ? ? ? ? ? ? ? try
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? switch (toolPar.RunPar.QrMode)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? case QrMode.QR:
? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeType = "QR Code";
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case QrMode.DM:
? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeType = "Data Matrix ECC 200";
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? switch (toolPar.RunPar.QrRecognition)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? case QRRecognition.standard_recognition:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ParamValue = "standard_recognition";
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case QRRecognition.enhanced_recognition:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ParamValue = "enhanced_recognition";
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case QRRecognition.maximum_recognition:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ParamValue = "maximum_recognition";
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? if(modelID == null)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.CreateDataCode2dModel((HTuple)CodeType, (HTuple)ParamName, (HTuple)ParamValue, out modelID);
? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? catch (Exception)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? status = false;
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? //return 0;
? ? ? ? ? ? }

? ? ? ? ? ? private void clearhandle()
? ? ? ? ? ? {
? ? ? ? ? ? ? ? HOperatorSet.ClearDataCode2dModel(modelID);
? ? ? ? ? ? }

? ? ? ? ? ? public void run()
? ? ? ? ? ? {
? ? ? ? ? ? ? ? creathandle();
? ? ? ? ? ? ? ? try
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? toolPar.ResultPar.CodeResult = new List<BarcodeResult>();
? ? ? ? ? ? ? ? ? ? if (modelID == null)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? status = false;
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? if (toolPar.InputPar.圖像 != null)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? if (toolPar.InputPar.ROI != null)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.ReduceDomain(toolPar.InputPar.圖像, toolPar.InputPar.ROI, out image);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? image = toolPar.InputPar.圖像;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? //設置極性
? ? ? ? ? ? ? ? ? ? ? ? string codePolarity= "dark_on_light";
? ? ? ? ? ? ? ? ? ? ? ? switch (toolPar.RunPar.CodePolarity)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? case CodePolarity.any: codePolarity = "any"; break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case CodePolarity.positive: codePolarity = "dark_on_light"; break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? case CodePolarity.negative: codePolarity = "light_on_dark"; break;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.SetDataCode2dParam(modelID, "polarity", codePolarity);
? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.SetDataCode2dParam(modelID, "timeout", toolPar.RunPar.TimeOut);
? ? ? ? ? ? ? ? ? ? ? ? HObject xlds;
? ? ? ? ? ? ? ? ? ? ? ? HTuple strtmp, resultHandles;
? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.FindDataCode2d(image,
? ? ? ? ? ? ? ? ? ? ? ? ? ? out xlds,
? ? ? ? ? ? ? ? ? ? ? ? ? ? modelID,
? ? ? ? ? ? ? ? ? ? ? ? ? ? "stop_after_result_num", toolPar.RunPar.CodeNum,
? ? ? ? ? ? ? ? ? ? ? ? ? ? out resultHandles,
? ? ? ? ? ? ? ? ? ? ? ? ? ? out strtmp);


? ? ? ? ? ? ? ? ? ? ? ? //把結果塞進去
? ? ? ? ? ? ? ? ? ? ? ? for (int i = 0; i < strtmp.Length; i++)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? BarcodeResult tmp;
? ? ? ? ? ? ? ? ? ? ? ? ? ? HObject region;
? ? ? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.GenRegionContourXld(xlds, out region, "filled");
? ? ? ? ? ? ? ? ? ? ? ? ? ? tmp.region = region;
? ? ? ? ? ? ? ? ? ? ? ? ? ? tmp.code = strtmp[i].S;
? ? ? ? ? ? ? ? ? ? ? ? ? ? toolPar.ResultPar.CodeResult.Add(tmp);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? toolPar.ResultPar.CodeNum = strtmp.Length;

? ? ? ? ? ? ? ? ? ? ? ? //HOperatorSet.clear

? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? status = false;
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? catch (Exception)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? clearhandle();
? ? ? ? ? ? ? ? ? ? status = false;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? clearhandle();
? ? ? ? ? ? }

? ? ? ? ? ? [Serializable]
? ? ? ? ? ? public class ToolPar : ToolParBase
? ? ? ? ? ? {
? ? ? ? ? ? ? ? private InputPar _inputPar = new InputPar();
? ? ? ? ? ? ? ? public InputPar InputPar
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _inputPar; }
? ? ? ? ? ? ? ? ? ? set { _inputPar = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? private RunPar _runPar = new RunPar();
? ? ? ? ? ? ? ? public RunPar RunPar
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _runPar; }
? ? ? ? ? ? ? ? ? ? set { _runPar = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? private ResultPar _resultPar = new ResultPar();
? ? ? ? ? ? ? ? public ResultPar ResultPar
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _resultPar; }
? ? ? ? ? ? ? ? ? ? set { _resultPar = value; }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? [Serializable]
? ? ? ? ? ? public class InputPar
? ? ? ? ? ? {
? ? ? ? ? ? ? ? private HObject _圖像;
? ? ? ? ? ? ? ? public HObject 圖像
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _圖像; }
? ? ? ? ? ? ? ? ? ? set { _圖像 = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? private HObject _ROI;
? ? ? ? ? ? ? ? public HObject ROI
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _ROI; }
? ? ? ? ? ? ? ? ? ? set { _ROI = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? private HObject _屏蔽區域;
? ? ? ? ? ? ? ? public HObject 屏蔽區域
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _屏蔽區域; }
? ? ? ? ? ? ? ? ? ? set { _屏蔽區域 = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? public int FindCodeNum { set; get; } = 1;


? ? ? ? ? ? }
? ? ? ? ? ? [Serializable]
? ? ? ? ? ? public class RunPar
? ? ? ? ? ? {
? ? ? ? ? ? ? ? public QRRecognition QrRecognition { get; set; }
? ? ? ? ? ? ? ? public QrMode QrMode { get; set; }
? ? ? ? ? ? ? ? public CodePolarity CodePolarity { get; set; }

? ? ? ? ? ? ? ? public int TimeOut { get; set; }

? ? ? ? ? ? ? ? public int CodeNum { get; set; }
? ? ? ? ? ? }
? ? ? ? ? ? [Serializable]
? ? ? ? ? ? public class ResultPar
? ? ? ? ? ? {
? ? ? ? ? ? ? ? private List<BarcodeResult> _CodeResult;
? ? ? ? ? ? ? ? public List<BarcodeResult> CodeResult
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _CodeResult; }
? ? ? ? ? ? ? ? ? ? set { _CodeResult = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? private int _CodeNum;
? ? ? ? ? ? ? ? public int CodeNum
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _CodeNum; }
? ? ? ? ? ? ? ? ? ? set { _CodeNum = value; }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? public class One_dimension
? ? ? ? {
? ? ? ? ? ? public ToolPar toolPar = new ToolPar();
? ? ? ? ? ? public bool status = true;
? ? ? ? ? ? internal HObject image = null;

? ? ? ? ? ? //條形碼識別句柄
? ? ? ? ? ? internal HTuple modelID = null;
? ? ? ? ? ? internal HTuple codetype = "auto";

? ? ? ? ? ? private void creathandle()
? ? ? ? ? ? {
? ? ? ? ? ? ? ? try
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? HOperatorSet.CreateBarCodeModel(new HTuple(), new HTuple(), out modelID);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? catch (Exception)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? status = false;
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? //return 0;
? ? ? ? ? ? }

? ? ? ? ? ? private void clearhandle()
? ? ? ? ? ? {
? ? ? ? ? ? ? ? HOperatorSet.ClearBarCodeModel(modelID);
? ? ? ? ? ? }

? ? ? ? ? ? public void run()
? ? ? ? ? ? {
? ? ? ? ? ? ? ? creathandle();
? ? ? ? ? ? ? ? toolPar.ResultPar.CodeResult = new List<BarcodeResult>();
? ? ? ? ? ? ? ? try
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? if (modelID == null)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? status = false;
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? if (toolPar.InputPar.圖像 != null)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? if (toolPar.InputPar.ROI != null)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.ReduceDomain(toolPar.InputPar.圖像, toolPar.InputPar.ROI, out image);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? image = toolPar.InputPar.圖像;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? HObject region;
? ? ? ? ? ? ? ? ? ? ? ? HTuple strtmp;

? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.SetBarCodeParam(modelID, "timeout", toolPar.RunPar.TimeOut);
? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.SetBarCodeParam(modelID, "stop_after_result_num", toolPar.RunPar.CodeNum);

? ? ? ? ? ? ? ? ? ? ? ? 設置極性
? ? ? ? ? ? ? ? ? ? ? ? //string codePolarity = "dark_on_light";
? ? ? ? ? ? ? ? ? ? ? ? //switch (toolPar.RunPar.CodePolarity)
? ? ? ? ? ? ? ? ? ? ? ? //{
? ? ? ? ? ? ? ? ? ? ? ? // ? ?case CodePolarity.any: codePolarity = "any"; break;
? ? ? ? ? ? ? ? ? ? ? ? // ? ?case CodePolarity.positive: codePolarity = "dark_on_light"; break;
? ? ? ? ? ? ? ? ? ? ? ? // ? ?case CodePolarity.negative: codePolarity = "light_on_dark"; break;
? ? ? ? ? ? ? ? ? ? ? ? //}
? ? ? ? ? ? ? ? ? ? ? ? //HOperatorSet.SetBarCodeParam(modelID, "polarity", codePolarity);
? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.FindBarCode(image, out region, modelID, codetype, out strtmp);

? ? ? ? ? ? ? ? ? ? ? ? //把結果塞進去
? ? ? ? ? ? ? ? ? ? ? ? for (int i = 0; i < strtmp.Length; i++)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? BarcodeResult tmp;
? ? ? ? ? ? ? ? ? ? ? ? ? ? tmp.region = region;
? ? ? ? ? ? ? ? ? ? ? ? ? ? tmp.code = strtmp[i].S;
? ? ? ? ? ? ? ? ? ? ? ? ? ? toolPar.ResultPar.CodeResult.Add(tmp);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? toolPar.ResultPar.CodeNum = strtmp.Length;

? ? ? ? ? ? ? ? ? ? ? ? //HOperatorSet.clear

? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? status = false;
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? catch (Exception)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? clearhandle();
? ? ? ? ? ? ? ? ? ? status = false;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? clearhandle();
? ? ? ? ? ? }


? ? ? ? ? ? [Serializable]
? ? ? ? ? ? public class ToolPar : ToolParBase
? ? ? ? ? ? {
? ? ? ? ? ? ? ? private InputPar _inputPar = new InputPar();
? ? ? ? ? ? ? ? public InputPar InputPar
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _inputPar; }
? ? ? ? ? ? ? ? ? ? set { _inputPar = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? private RunPar _runPar = new RunPar();
? ? ? ? ? ? ? ? public RunPar RunPar
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _runPar; }
? ? ? ? ? ? ? ? ? ? set { _runPar = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? private ResultPar _resultPar = new ResultPar();
? ? ? ? ? ? ? ? public ResultPar ResultPar
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _resultPar; }
? ? ? ? ? ? ? ? ? ? set { _resultPar = value; }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? [Serializable]
? ? ? ? ? ? public class InputPar
? ? ? ? ? ? {
? ? ? ? ? ? ? ? private HObject _圖像;
? ? ? ? ? ? ? ? public HObject 圖像
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _圖像; }
? ? ? ? ? ? ? ? ? ? set { _圖像 = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? private HObject _ROI;
? ? ? ? ? ? ? ? public HObject ROI
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _ROI; }
? ? ? ? ? ? ? ? ? ? set { _ROI = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? private HObject _屏蔽區域;
? ? ? ? ? ? ? ? public HObject 屏蔽區域
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _屏蔽區域; }
? ? ? ? ? ? ? ? ? ? set { _屏蔽區域 = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? }
? ? ? ? ? ? [Serializable]
? ? ? ? ? ? public class RunPar
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //public BarRecognition BarRecognition { get; set; }
? ? ? ? ? ? ? ? public BarMode BarMode { get; set; }
? ? ? ? ? ? ? ? public CodePolarity CodePolarity { get; set; }

? ? ? ? ? ? ? ? public int TimeOut { get; set; }

? ? ? ? ? ? ? ? public int CodeNum { get; set; }
? ? ? ? ? ? }
? ? ? ? ? ? [Serializable]
? ? ? ? ? ? public class ResultPar
? ? ? ? ? ? {
? ? ? ? ? ? ? ? private List<BarcodeResult> _CodeResult;
? ? ? ? ? ? ? ? public List<BarcodeResult> CodeResult
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _CodeResult; }
? ? ? ? ? ? ? ? ? ? set { _CodeResult = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? private int _CodeNum;
? ? ? ? ? ? ? ? public int CodeNum
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _CodeNum; }
? ? ? ? ? ? ? ? ? ? set { _CodeNum = value; }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? public class OCR
? ? ? ? {
? ? ? ? ? ? public ToolPar toolPar = new ToolPar();
? ? ? ? ? ? public bool status = true;
? ? ? ? ? ? internal HObject image = null;
? ? ? ? ? ? RunPar runPar=new RunPar ();
? ? ? ? ? ? public void run()
? ? ? ? ? ? {

? ? ? ? ? ? ? ? try
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? if (toolPar.InputPar.圖像 != null)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? if (toolPar.InputPar.ROI != null && toolPar.InputPar.屏蔽區域 != null)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? HObject reduce_region = new HObject();
? ? ? ? ? ? ? ? ? ? ? ? ? ? reduce_region.Dispose();
? ? ? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.Difference(toolPar.InputPar.ROI, toolPar.InputPar.屏蔽區域, out reduce_region);
? ? ? ? ? ? ? ? ? ? ? ? ? ? //image.Dispose();
? ? ? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.ReduceDomain(toolPar.InputPar.圖像, reduce_region, out image);
? ? ? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.CropDomain(image, out image);
? ? ? ? ? ? ? ? ? ? ? ? ? ? reduce_region.Dispose();
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? else if (toolPar.InputPar.ROI != null && toolPar.InputPar.屏蔽區域 == null)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.GenEmptyObj(out image);
? ? ? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.ReduceDomain(toolPar.InputPar.圖像, toolPar.InputPar.ROI, out image);
? ? ? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.CropDomain(image, out image);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? else if (toolPar.InputPar.ROI == null && toolPar.InputPar.屏蔽區域 != null)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? HObject reduce_region = new HObject();
? ? ? ? ? ? ? ? ? ? ? ? ? ? reduce_region.Dispose();
? ? ? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.Difference(toolPar.InputPar.圖像, toolPar.InputPar.屏蔽區域, out reduce_region);
? ? ? ? ? ? ? ? ? ? ? ? ? ? //image.Dispose();
? ? ? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.ReduceDomain(toolPar.InputPar.圖像, reduce_region, out image);
? ? ? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.CropDomain(image, out image);
? ? ? ? ? ? ? ? ? ? ? ? ? ? reduce_region.Dispose();
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (image != null)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? image.Dispose();
? ? ? ? ? ? ? ? ? ? ? ? ? ? image = toolPar.InputPar.圖像;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? status = false;
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? //初始化
? ? ? ? ? ? ? ? ? ? //ocr_engine.OCR_INIT();
? ? ? ? ? ? ? ? ? ? //HObject img;
? ? ? ? ? ? ? ? ? ? //HOperatorSet.GenEmptyObj(out img);
? ? ? ? ? ? ? ? ? ? //img = image;
? ? ? ? ? ? ? ? ? ? 檢測
? ? ? ? ? ? ? ? ? ? //string ocr_result = ocr_engine.OCR_Dect(img);
? ? ? ? ? ? ? ? ? ? //ocr_engine.engine.Dispose();
? ? ? ? ? ? ? ? ? ? //toolPar.ResultPar.OCRResult = ocr_result;
? ? ? ? ? ? ? ? ? ? //ocr_result = String.Empty;

? ? ? ? ? ? ? ? ? ? HOperatorSet.CountChannels(image, out var channels);
? ? ? ? ? ? ? ? ? ? Bitmap img;
? ? ? ? ? ? ? ? ? ? HObject multiChannelImage;
? ? ? ? ? ? ? ? ? ? HOperatorSet.GenEmptyObj(out multiChannelImage);
? ? ? ? ? ? ? ? ? ? if (channels == 3)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? img=runPar.Honject2Bitmap24(image);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? HOperatorSet.Compose3(image, image, image, out multiChannelImage);
? ? ? ? ? ? ? ? ? ? ? ? img = runPar.Honject2Bitmap24(multiChannelImage);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? runPar.ocrResult= runPar.engine.DetectText(img);
? ? ? ? ? ? ? ? ? ? toolPar.ResultPar.OCRResult = runPar.ocrResult.Text;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? catch (Exception)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? status = false;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }

? ? ? ? ? ? [Serializable]
? ? ? ? ? ? public class ToolPar : ToolParBase
? ? ? ? ? ? {
? ? ? ? ? ? ? ? private InputPar _inputPar = new InputPar();
? ? ? ? ? ? ? ? public InputPar InputPar
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _inputPar; }
? ? ? ? ? ? ? ? ? ? set { _inputPar = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? private RunPar _runPar = new RunPar();
? ? ? ? ? ? ? ? public RunPar RunPar
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _runPar; }
? ? ? ? ? ? ? ? ? ? set { _runPar = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? private ResultPar _resultPar = new ResultPar();
? ? ? ? ? ? ? ? public ResultPar ResultPar
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _resultPar; }
? ? ? ? ? ? ? ? ? ? set { _resultPar = value; }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? [Serializable]
? ? ? ? ? ? public class InputPar
? ? ? ? ? ? {
? ? ? ? ? ? ? ? private HObject _圖像;
? ? ? ? ? ? ? ? public HObject 圖像
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _圖像; }
? ? ? ? ? ? ? ? ? ? set { _圖像 = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? private HObject _ROI;
? ? ? ? ? ? ? ? public HObject ROI
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _ROI; }
? ? ? ? ? ? ? ? ? ? set { _ROI = value; }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? private HObject _屏蔽區域;
? ? ? ? ? ? ? ? public HObject 屏蔽區域
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? get { return _屏蔽區域; }
? ? ? ? ? ? ? ? ? ? set { _屏蔽區域 = value; }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? [Serializable]
? ? ? ? ? ? public class RunPar
? ? ? ? ? ? {
? ? ? ? ? ? ? ? public OCRModelConfig config = null;

? ? ? ? ? ? ? ? public OCRParameter oCRParameter = new OCRParameter();

? ? ? ? ? ? ? ? public OCRResult ocrResult = new OCRResult();

? ? ? ? ? ? ? ? public PaddleOCREngine engine;

? ? ? ? ? ? ? ? public RunPar()
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? engine = new PaddleOCREngine(config, oCRParameter);
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? [DllImport("kernel32.dll")]
? ? ? ? ? ? ? ? public static extern void CopyMemory(int Destination, int add, int Length);

? ? ? ? ? ? ? ? public Bitmap Honject2Bitmap24(HObject hObject)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? HTuple width = new HTuple();
? ? ? ? ? ? ? ? ? ? HTuple height = new HTuple();
? ? ? ? ? ? ? ? ? ? HTuple pointer = new HTuple();
? ? ? ? ? ? ? ? ? ? HTuple type = new HTuple();
? ? ? ? ? ? ? ? ? ? HTuple width2 = new HTuple();
? ? ? ? ? ? ? ? ? ? HTuple height2 = new HTuple();
? ? ? ? ? ? ? ? ? ? HObject interleavedImage = new HObject();
? ? ? ? ? ? ? ? ? ? HOperatorSet.GetImageSize(hObject, out width, out height);
? ? ? ? ? ? ? ? ? ? HOperatorSet.InterleaveChannels(hObject, out interleavedImage, "rgb", 4 * width, 0);
? ? ? ? ? ? ? ? ? ? HOperatorSet.GetImagePointer1(interleavedImage, out pointer, out type, out width2, out height2);
? ? ? ? ? ? ? ? ? ? IntPtr scan = pointer;
? ? ? ? ? ? ? ? ? ? return new Bitmap(width2 / 4, height2, width2, PixelFormat.Format24bppRgb, scan);
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? public void HObject2Bitmap8(HObject image, out Bitmap res)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? HOperatorSet.GetImagePointer1(image, out var pointer, out var _, out var width, out var height);
? ? ? ? ? ? ? ? ? ? res = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
? ? ? ? ? ? ? ? ? ? ColorPalette palette = res.Palette;
? ? ? ? ? ? ? ? ? ? for (int i = 0; i <= 255; i++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? palette.Entries[i] = Color.FromArgb(255, i, i, i);
? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? res.Palette = palette;
? ? ? ? ? ? ? ? ? ? System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);
? ? ? ? ? ? ? ? ? ? BitmapData bitmapData = res.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
? ? ? ? ? ? ? ? ? ? int num = Image.GetPixelFormatSize(bitmapData.PixelFormat) / 8;
? ? ? ? ? ? ? ? ? ? IntPtr scan = bitmapData.Scan0;
? ? ? ? ? ? ? ? ? ? IntPtr source = pointer;
? ? ? ? ? ? ? ? ? ? int num2 = width * height;
? ? ? ? ? ? ? ? ? ? byte[] array = new byte[num2];
? ? ? ? ? ? ? ? ? ? Marshal.Copy(source, array, 0, num2);
? ? ? ? ? ? ? ? ? ? Marshal.Copy(array, 0, scan, num2);
? ? ? ? ? ? ? ? ? ? res.UnlockBits(bitmapData);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? [Serializable]
? ? ? ? ? ? public class ResultPar
? ? ? ? ? ? {
? ? ? ? ? ? ? ? private string _OCRResult { get; set; }
? ? ? ? ? ? ? ? public string OCRResult { get { return _OCRResult; } set { _OCRResult = value; } }
? ? ? ? ? ? }

? ? ? ? }

? ? }
}
?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/12762.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/12762.shtml
英文地址,請注明出處:http://en.pswp.cn/web/12762.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【Kafka】2.深入理解Kafka事件流平臺及其核心概念

1.事件流(Event streaming) 事件流是人體中樞神經系統的數字化的等價物。它是構建“始終在線”世界的技術基礎&#xff0c;在這個世界中&#xff0c;企業越來越多地被定義為軟件化和自動化&#xff0c;而軟件的用戶本身也是軟件。 從技術上講&#xff0c;事件流是從數據庫、傳…

vue2 雙向數據綁定的實現及原理

Oject.defineProperty() 是 JavaScript 中用于定義或修改對象的屬性的方法&#xff0c;可以控制屬性的特性&#xff08;如可枚舉性、可配置性、可寫性等&#xff09; Object.defineProperty(obj, prop, descriptor) obj&#xff1a;要在其上定義屬性的對象。 prop&#xff1a;要…

P7222 [RC-04] 信息學競賽

文章目錄 題目[RC-04] 信息學競賽題目描述輸入格式輸出格式樣例 #1樣例輸入 #1樣例輸出 #1 提示 思路AC代碼 題目 [RC-04] 信息學競賽 題目描述 小 R 今天學習了余角有關的數學知識&#xff0c;請你幫幫他計算一個角的余角吧&#xff01; 一個角的余角的計算公式如下&#…

SHELL編程(一)

目錄 一、 Linux操作系統&#xff08;一&#xff09;內核與操作系統&#xff08;二&#xff09;操作系統的功能 二、Linux高級命令&#xff08;一&#xff09; 離線安裝 dpkg1. 安裝2. 使用3. 查看安裝詳細信息4. 安裝路徑5. 不完全刪除6. 完全刪除 &#xff08;二&#xff09;…

KNN算法用于回歸分析

生成數據集 from sklearn.datasets import make_regression import matplotlib.pyplot as plt# 生成特征數量為1&#xff0c; 噪音為50的數據集 X, y make_regression(n_features1, n_informative1, noise50, random_state8)# 散點圖 plt.scatter(X, y, c"orange",…

什么是TCP的粘包、拆包問題?

一、問題解析 TCP粘包和拆包問題是指在進行TCP通信時&#xff0c;因為TCP是面向流的&#xff0c;所以發送方在傳輸數據時可能會將多個小的數據包粘合在一起發送&#xff0c;而接收方則可能將這些數據包拆分成多個小的數據包進行接收&#xff0c;從而導致數據接收出現錯誤或者數…

uniapp swiper添加點擊切換 上一張 下一張

<view click"switchPrev"><text>上一張</text> </view> <view click"switchNext"><text>下一張</text> </view> <swiper class"swiper" circular :current"current"> data() {…

MySQL數據庫練習二

素材&#xff1a;表名&#xff1a;worker-- 表中字段均為中文&#xff0c;比如部門號、工資、職工號、參加工作等 CREATE TABLE worker (部門號 int(11) NOT NULL,職工號 int(11) NOT NULL,工作時間 date NOT NULL,工資 float(8,2) NOT NULL,政治面貌 varchar(10) NOT NULL DE…

歡樂釣魚大師攻略大全,新手釣魚入坑必備攻略!

《歡樂釣魚大師》是一款深受玩家喜愛的釣魚手游&#xff0c;在游戲中&#xff0c;玩家可以通過升級和更換魚竿來享受釣魚的樂趣&#xff0c;并有機會釣到各種稀有魚類。然而&#xff0c;很多玩家在闖關過程中遇到了不少困難。為了幫助大家更好地掌握游戲技巧&#xff0c;小編特…

4 軟件定義安全綜合:使用c/s模式進行控制器數據安全交互管理

在SDN三層結構中&#xff0c;我們通過OpenFlow 協議可以控制數據轉發設備的相關行為&#xff08;包括收集設備的信息&#xff09;&#xff0c;那么控制器上的數據能否通過應用層的程序進行管理調用呢&#xff1f; SDN&#xff08;軟件定義網絡&#xff09;的北向開發是指通過編…

ASUS Zenbook PE重裝系統后一直轉圈不斷重啟

問題描述&#xff1a; ASUS Zenbook PE重裝系統后一直轉圈不斷重啟 問題原因&#xff1a; RST驅動問題 解決辦法&#xff1a; 使用U盤安裝原版系統&#xff0c;安裝過程中&#xff0c;發現磁盤頁面沒有不識別硬盤&#xff0c;此時選擇加載驅動&#xff0c;加載RST驅動。一…

二進制搭建k8s

實驗環境&#xff1a; k8s集群master01:192.168.1.11 k8s集群master02:192.168.1.22 master虛擬ip&#xff1a;192.168.1.100 k8s集群node01:192.168.1.33 k8s集群node01:192.168.1.44 nginxkeepalive01&#xff08;master&#xff09;:192.168.1.55 nginxkeepalive02&a…

渲染農場是什么意思?瑞云渲染為你解答

渲染農場是一種通過集合多臺計算機的計算能力來加速圖像渲染過程的系統。它尤其適用于動畫、電影特效和高端視覺效果的制作&#xff0c;這些領域通常需要處理非常復雜和計算密集型的渲染任務。 渲染農場就是一大群電腦&#xff0c;他們一起可以快速渲染出漂亮的圖像。在做動畫片…

客觀需求驗證的常見5大步驟(實施版)

我們在挖掘用戶需求時&#xff0c;往往容易犯偽需求或需求錯位等問題&#xff0c;因此需要進行客觀需求驗證。通過客觀的驗證&#xff0c;我們可以有效減少主觀判斷誤差問題&#xff0c;確保需求的準確性&#xff0c;從而降低需求變更和項目風險的概率&#xff0c;減少開發成本…

LeetCode算法題:11. 盛最多水的容器(Java)(雙指針問題總結)

給定一個長度為 n 的整數數組 height 。有 n 條垂線&#xff0c;第 i 條線的兩個端點是 (i, 0) 和 (i, height[i]) 。 找出其中的兩條線&#xff0c;使得它們與 x 軸共同構成的容器可以容納最多的水。 返回容器可以儲存的最大水量。 提示&#xff1a; n height.length2 <…

第十四屆藍橋杯大賽軟件賽國賽C/C++ 大學 B 組 數三角

//枚舉頂點。 //不存在等邊三角形 #include<bits/stdc.h> using namespace std; #define int long long const int n2e311; int a,b,c,l[n],r[n]; signed main() {ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);cin>>a;for(int i1;i<a;i){cin>>…

UE4_環境_局部霧化效果

學習筆記&#xff0c;不喜勿噴&#xff01;侵權立刪&#xff01;祝愿大家生活越來越好&#xff01; 本文重點介紹下材質節點SphereMask節點在體積霧中的使用方法。 一、球體遮罩SphereMask材質節點介紹&#xff1a; 球體蒙版&#xff08;SphereMask&#xff09; 表達式根據距…

【筆記】Android Studio 版本信息

Android Studio Jellyfish | 2023.3.1 | Android Developers Android Studio 是開發 Android 應用的官方 IDE&#xff0c;包含構建 Android 應用所需的所有功能。 AS與AGP版本適用關系 AGP(Android Gradle plugin) Android gradle插件 Androdi Studio versionRequired AG…

2024紅帽全球峰會:CEO行業洞察分享

作為全球IT領域一年一度的行業盛宴&#xff0c;2024紅帽全球峰會于近日盛大召開。生成式AI與大模型是當前IT行業最受關注的熱點話題&#xff0c;而紅帽在生成式AI與大模型領域的最新動作&#xff0c;也理所當然地成為了本屆峰會觀眾目光聚集的焦點。 作為世界領先的開源解決方案…

使用vcpkg與json文件自動安裝項目依賴庫

說明 本文記錄自己使用vcpkg.json文件自動安裝依賴庫并完成編譯的全過程。 關于vcpkg是什么這里就不多詳細解釋&#xff0c;可以看一下專門的介紹及安裝的文章&#xff0c;總之了解這是一個C的包管理工具就可以了。 流程 下面介紹從GitHub上克隆C項目以及為這個項目安裝所需…