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();
}
}
}