在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → 车号图像采集系统(巴斯勒采图软件原码)

车号图像采集系统(巴斯勒采图软件原码)

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:0.53M
  • 下载次数:43
  • 浏览次数:326
  • 发布时间:2019-06-04
  • 实例类别:C#语言基础
  • 发 布 人:zougl
  • 文件格式:.rar
  • 所需积分:2
 相关标签: 软件

实例介绍

【实例简介】

【实例截图】

from clipboard

【核心代码】

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using Pylon.BaslerGige;
using System.IO;

namespace CH_Tds
{
    public partial class mainForm : Form
    {
        public mainForm()
        {
            InitializeComponent();
            iniAlarmListBox();
        }
        /// <summary>
        /// 界面来车
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 界面拍照
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {
            //device.SoftwareTrigger();

        }
        /// <summary>
        /// 界面离车
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 界面清除日志
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button6_Click(object sender, EventArgs e)
        {
            alarmListBox.Items.Clear();
        }
        /// <summary>
        /// 查看文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button7_Click(object sender, EventArgs e)
        {
            try { System.Diagnostics.Process.Start(@"d:\train_data\Image"); }
            catch { }

        }
        /// <summary>
        /// 模拟连接系统
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button8_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 界面增加运行日志记录
        /// </summary>
        /// <param name="str"></param>
        public void addRunMessage(string str)
        {
            //写入文件
            string strTemp = str;
            Mydelegate mydelegate = (string str1) =>
            {
                this.alarmListBox.Items.Add(str1);
                this.alarmListBox.SelectedIndex = this.alarmListBox.Items.Count - 1;
            };
            try { this.alarmListBox.Invoke(mydelegate, str); }
            catch { }
        }
        private delegate void Mydelegate(string str);
        private void iniAlarmListBox()
        {
            this.alarmListBox.SelectionMode = SelectionMode.One;
            this.alarmListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
            this.alarmListBox.DrawItem  = alarmListBox_DrawItem;           //alarmListBox窗体绘制事件
            this.alarmListBox.ItemHeight = 23;
            this.alarmListBox.Font = new Font(this.alarmListBox.Font.FontFamily, 16);
            this.alarmListBox.Height  = 4;
        }
        /// <summary>
        /// alarmListBox选项颜色更新,使用其内部事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void alarmListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            try
            {
                e.DrawBackground();
                Brush mybsh = Brushes.Black;
                //判断是什么类型的标签  
                if (alarmListBox.Items[e.Index].ToString().Contains("!") || alarmListBox.Items[e.Index].ToString().Contains("!"))
                    mybsh = Brushes.Red;
                else mybsh = Brushes.Black;
                e.DrawFocusRectangle();
                e.Graphics.DrawString(alarmListBox.Items[e.Index].ToString(), e.Font, mybsh, e.Bounds, StringFormat.GenericDefault);
            }
            catch { }
        }
        /// <summary>
        /// 查看日志
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            try
            { System.Diagnostics.Process.Start(@"D:\train_data\runLog"); }
            catch { }

        }
        #region  窗体移动
        private Point downPoint;
        /// <summary>
        /// 窗体移动前
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void formMouseDown(object sender, MouseEventArgs e)
        {
            downPoint = new Point(e.X, e.Y);
        }
        /// <summary>
        /// 窗体移动后
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void formMouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Location = new Point(this.Location.X   e.X - downPoint.X,
                                this.Location.Y   e.Y - downPoint.Y);
            }
        }

        /// <summary>
        /// 主窗体加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mainForm_Load(object sender, EventArgs e)
        {
            /*窗体移动*/
            this.label2.MouseDown  = new System.Windows.Forms.MouseEventHandler(this.formMouseDown);
            this.pictureBox1.MouseDown  = new System.Windows.Forms.MouseEventHandler(this.formMouseDown);
            this.label1.MouseDown  = new System.Windows.Forms.MouseEventHandler(this.formMouseDown);
            this.button1.MouseDown  = new System.Windows.Forms.MouseEventHandler(this.formMouseDown);
            this.label5.MouseDown  = new System.Windows.Forms.MouseEventHandler(this.formMouseDown);

            this.label2.MouseMove  = new System.Windows.Forms.MouseEventHandler(this.formMouseMove);
            this.pictureBox1.MouseMove  = new System.Windows.Forms.MouseEventHandler(this.formMouseMove);
            this.label1.MouseMove  = new System.Windows.Forms.MouseEventHandler(this.formMouseMove);
            this.button1.MouseMove  = new System.Windows.Forms.MouseEventHandler(this.formMouseMove);
            this.label5.MouseMove  = new System.Windows.Forms.MouseEventHandler(this.formMouseMove);
            iniTimeFresh();//界面时间刷新

            CameraData camerData = new CameraData();
            {
                DirectoryInfo dir = new DirectoryInfo(Application.StartupPath).Parent.Parent;//bin文件夹
                string path = dir.FullName   "\\relatedFiles\\camera.ini";
                CIni cini = new CIni(path);
                camerData.serialNumber = cini.ReadValue("camera", "serialNumber");
                camerData.userID = cini.ReadValue("camera", "userID");
                camerData.IpAddress = cini.ReadValue("camera", "address");
            }
            device = new BaslerGigeCamera(camerData);
            device.MonitorCameraStatus  = device_MonitorCameraStatus;
            device.GrabedImage  = device_GrabedImage;


            //this.button10.Enabled = false;
        }
        private BaslerGigeCamera device = null; //相机设备对象
        /// <summary>
        /// 相机拍照图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void device_GrabedImage(CameraObject sender, BitmapEventArgs e)
        {
            System.DateTime currentTime = new System.DateTime();
            currentTime = System.DateTime.Now;
            int currentMonth = currentTime.Month;
            int currentDay = currentTime.Day;
            int currentHour = currentTime.Hour;                 //小时
            int currentMinute = currentTime.Minute;             //分钟
            int currentSecond = currentTime.Second;             //秒
            int Millisecond = currentTime.Millisecond;          //微秒
            string str = string.Format("{0:D2}", currentHour)   ":"   string.Format("{0:D2}", currentMinute)   ":"  
                string.Format("{0:D2}", currentSecond)   ":"   string.Format("{0:D3}", Millisecond)   "      "   sender.cameraData.userID   "相机("   sender.cameraData.IpAddress   ")采图";
            CTxt.writeTxt(str);
            try
            {
                this.addRunMessage(str);
            }
            catch { }

            try
            {
                Bitmap bitmap = e.bitmap;
                string foldPath = @"D:\train_data\image\"   DateTime.Now.ToString("yyyyMMdd")   @"_"   string.Format("{0:D2}", currentHour)   @"_"   string.Format("{0:D2}", currentMinute);//文件夹名
                if (!Directory.Exists(foldPath))
                    Directory.CreateDirectory(foldPath);
                string savePath = foldPath   "\\"   string.Format("{0:D2}", currentMinute)   "_"   string.Format("{0:D2}", currentSecond)   "_"   string.Format("{0:D3}", Millisecond)   ".jpg";
                bitmap.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch { }
        }
        /// <summary>
        /// 监视相机状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void device_MonitorCameraStatus(CameraObject sender, CameraStatusEventArgs e)
        {
            System.DateTime currentTime = new System.DateTime();
            currentTime = System.DateTime.Now;
            int currentHour = currentTime.Hour;                 //小时
            int currentMinute = currentTime.Minute;             //分钟
            int currentSecond = currentTime.Second;             //秒
            string str = string.Format("{0:D2}", currentHour)   ":"   string.Format("{0:D2}", currentMinute)   ":"  
                string.Format("{0:D2}", currentSecond)   "      "   sender.cameraData.userID   "相机("   sender.cameraData.IpAddress   ")"   e.cameraRealStatus;
            CTxt.writeTxt(str);
            this.addRunMessage(str);
        }


       
        #endregion
        /// <summary>
        /// 刷新界面时间条
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void freshTime_Tick(object sender, EventArgs e)
        {
            System.DateTime currentTime = new System.DateTime();
            currentTime = System.DateTime.Now;
            int currentHour = currentTime.Hour;
            int currentMinute = currentTime.Minute;
            int currentSecond = currentTime.Second;
            label5.Text = string.Format("{0:D2}", currentHour)   ":"   string.Format("{0:D2}", currentMinute)   ":"  
                string.Format("{0:D2}", currentSecond);
        }
        /// <summary>
        /// 初始时间显示
        /// </summary>
        private void iniTimeFresh()
        {
            System.DateTime currentTime = new System.DateTime();
            currentTime = System.DateTime.Now;
            int currentHour = currentTime.Hour;
            int currentMinute = currentTime.Minute;
            int currentSecond = currentTime.Second;
            label5.Text = string.Format("{0:D2}", currentHour)   ":"   string.Format("{0:D2}", currentMinute)   ":"   string.Format("{0:D2}", currentSecond);
            freshTime.Start();
        }
        /// <summary>
        /// 最小化窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void smallButton_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }
        /// <summary>
        /// 关闭窗口指令
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            device.terminate();
            //Thread.Sleep(5);
            this.Close();
            return;


            //string msg = "确定退出系统吗?" ;
            //ExitForm frm = null;
            //int a = (int)MessageBox.Show(msg, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
            //if (a == 1) 
            //{
            //    frm = new ExitForm();
            //    frm.ShowDialog();
            //    if (frm.passIsTrue)
            //    {
            //        //总程序退出
            //        this.Close();
            //    }
            //}
            //else return;
        }

        /// <summary>
        /// 软触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button9_Click_1(object sender, EventArgs e)
        {
            new Thread(() =>
            {
                device.SoftwareTrigger();
            }).Start();
        }
        /// <summary>
        /// 硬触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button10_Click(object sender, EventArgs e)
        {
            new Thread(() =>
            {
                device.setLine1Mode();
            }).Start();
        }
    }
}

标签: 软件

实例下载地址

车号图像采集系统(巴斯勒采图软件原码)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

第 1 楼 sunyzth 发表于: 2019-08-14 15:05 10
不能使用呀

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有1条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警