Program.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using OpenCvSharp;
  2. using OpenCvSharp.Extensions;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Security.Cryptography.X509Certificates;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. namespace OpenCvSharpTest
  13. {
  14. internal class Program
  15. {
  16. static void Main(string[] args)
  17. {
  18. //Bitmap Bitmapimage = new Bitmap("D:\\work\\WindowsFormsTest\\OpenCvSharpTest\\Image_20231102165054144.bmp");
  19. Bitmap Bitmapimage = new Bitmap("D:\\work\\WindowsFormsTest\\TestImage\\20250609165353.jpg");
  20. Stopwatch stopwatch= Stopwatch.StartNew();
  21. ReadCodeTest.Read10CodeTest1(Bitmapimage);
  22. //ParticleDetectionTest.ParticleDetectionTest1(Bitmapimage);
  23. stopwatch.Stop();
  24. Console.WriteLine(stopwatch.ElapsedMilliseconds+"ms");
  25. Cv2.WaitKey(0);
  26. Console.ReadKey();
  27. //InstructionManualTest.InstructionManualTest1();
  28. }
  29. //static void ReadCode(Mat gray)
  30. //{
  31. // // 3. 初始化 ZXing 解码器
  32. // var reader = new BarcodeReader
  33. // {
  34. // Options = new DecodingOptions
  35. // {
  36. // TryHarder = true,
  37. // PossibleFormats = new List<BarcodeFormat> { BarcodeFormat.EAN_13, BarcodeFormat.CODE_128 }
  38. // }
  39. // };
  40. // var bitmap = BitmapConverter.ToBitmap(gray);
  41. // // 4. 解码条码
  42. // var result = reader.Decode(bitmap);
  43. // if (result != null)
  44. // {
  45. // Console.WriteLine("条码内容: " + result.Text);
  46. // Console.WriteLine("条码类型: " + result.BarcodeFormat);
  47. // }
  48. // else
  49. // {
  50. // Console.WriteLine("未检测到条码");
  51. // }
  52. //}
  53. static Mat ResizeMat(Mat mat)
  54. {
  55. Mat resizedImage = new Mat();
  56. double maxSize = 1000;
  57. double scale = Math.Min(maxSize / mat.Width, maxSize / mat.Height);
  58. OpenCvSharp.Size scaledSize = new OpenCvSharp.Size(mat.Width * scale, mat.Height * scale);
  59. Cv2.Resize(mat, resizedImage, scaledSize);
  60. return resizedImage;
  61. }
  62. }
  63. }