一维二码实时识别

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;
using System.Drawing;
 
using System.Text;
using System.Windows.Forms;
using System.IO;

using ZXing.QrCode;
using ZXing;
using ZXing.Common;

using Emgu;
using Emgu.CV;
using Emgu.CV.Stitching;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.CV.CvEnum;
using Emgu.CV.ML;

 

 
namespace 拖放二维码图片识别
{
    public partial class Form1 : Form
    {
        Capture _capture = new Capture();
        bool _calc = false;
  
        public Form1()
        {
           
            InitializeComponent();
           

            //string filename = @"D:\Emgu\emgu SU CODE\拖放二维码图片识别\拖放二维码图片识别\bin\Debug\generate3.bmp";
            //Bitmap a = new Bitmap(@"D:\Emgu\emgu SU CODE\拖放二维码图片识别\拖放二维码图片识别\bin\Debug\generate3.bmp");
            //string result = Read1(filename);
            //textBoxText.Text = result;
            //pictureBoxPic.Image = a;


            timer1.Enabled = true;


            _capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight, 3350);
            //设置捕捉到帧的高度为320。
            _capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth, 350);
            //设置捕捉到帧的宽度为240。
            _capture.FlipHorizontal = true;
            //捕捉到帧数据进行水平翻转。
            _capture.ImageGrabbed += new EventHandler(frame);
            //捕捉到帧数据执行线程。
            _capture.Start();
        
           
           
        }
        //public delegate  void AddCamera_use() ;
        //public   void SetCamera_use()
        //{
        //    this.Invoke(new AddCamera_use(RunAddCamera_use));
        // }
        //public void RunAddCamera_use()
        //{
        //    TreeNode TNode = new TreeNode();

        //}


        public static void Calculate()
        {
            DateTime time = DateTime.Now;//得到当前时间 
            Random ra = new Random();//随机数对象  
            Thread.Sleep(ra.Next(1000, 2000));//随机休眠一段时间
            string _string = time.ToString();

            // Console.WriteLine(time.Minute + ":" + time.Millisecond); 
        }

        private void frame(object sender, EventArgs e)//执行帧线程。
        {
            Mat _frame = new Mat();//创建Mat存储捕捉到的帧。
            _capture.Retrieve(_frame, 0);//进行帧捕捉。
            imageBox1.Image = _frame;//显示帧数据。
            imageBox1.Image.Save("generate3.bmp");
            Thread.Sleep(1000);
            //timer1.Tick += timer1_Tick; //增加事件处理函数
            _calc = true;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            //DateTime time = DateTime.Now;//得到当前时间  
            //string _string = time.ToString();
            //textBox1.Text = _string; 

            if (_calc)
            {
                _calc = false;
                string filename = @"D:\Emgu\emgu SU CODE\拖放二维码图片识别\拖放二维码图片识别\bin\Debug\generate3.bmp";
                string result = Read1(filename);
                textBoxText.Text = result;
                pictureBoxPic.Load(filename);
            }
        }

        /// <summary>
        /// 读取二维码
        /// 读取失败,返回空字符串
        /// </summary>
        /// <param name="filename">指定二维码图片位置</param>
        static string Read1(string filename)
        {
            BarcodeReader reader = new BarcodeReader();
            reader.Options.CharacterSet = "UTF-8";
            Bitmap map = new Bitmap(filename);
            Result result = reader.Decode(map);
            map.Dispose();
            return result == null ? "" : result.Text; 
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //ThreadStart threadStart = new ThreadStart(Calculate);
            //Thread thread = new Thread(threadStart);
            //thread.Start();
        }
        
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值