-1

我正在做一个车牌识别系统。我已将相机设置为每 10 秒捕获一次图像并将其存储在一个文件夹中。我可以知道如何获取或捕获日期和时间,并将其显示在文件夹中捕获的每张图像的标签中。我正在使用 C# 进行编码,并且还使用我的 USB 相机来捕获图像

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private FilterInfoCollection CaptureDevices;
        private VideoCaptureDevice videoSource;
        private Int32 pictureCount = 0;

        private void Form1_Load(object sender, EventArgs e)
        {
            CaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            foreach (FilterInfo Device in CaptureDevices)
            {
                cboDevice.Items.Add(Device.Name);
            }
            cboDevice.SelectedIndex = 0;
            videoSource = new VideoCaptureDevice();

            timer1.Tick += new EventHandler(this.timer1_Tick);
            timer1.Interval = (100) * (100);
            timer1.Enabled = true;
            timer1.Start();

            videoSource = new VideoCaptureDevice(CaptureDevices[cboDevice.SelectedIndex].MonikerString);
            videoSource.NewFrame += new NewFrameEventHandler(videoSource_NewFrame);
            videoSource.Start();

        }

        void videoSource_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
        {
            pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            pictureBox1.Image.Save(pictureCount.ToString() + ".jpg", ImageFormat.Jpeg);
            pictureCount++;
        }

    }

我希望在它捕获图像时,它会自动在标签上显示捕获图像的日期和时间。

4

1 回答 1

0

您可以编写一个可序列化的对象并将其保存/加载到文件中。

    private void SampleLoadPicture(string fileName)
    {
        var imageDate = ImageDate.Load(fileName);
        // Store in a database:
        // imageDate.CapturedImage;
        // imageDate.CapturedDateTime;
    }
    private void timer1_Tick(object sender, EventArgs e)
    {
        var imageDate = new ImageDate((Bitmap)pictureBox1.Image, DateTime.Now);
        imageDate.Save(pictureCount.ToString() + ".IMGDATE");
        pictureCount++;
    }
    [Serializable]
    public class ImageDate
    {
        public Bitmap CapturedImage { get; set; }
        public DateTime CapturedDateTime { get; set; }
        public void Save(string fileName)
        {
            using (FileStream fs = new FileStream(fileName, FileMode.Create))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(fs, this);
            }
        }
        public static ImageDate Load(string fileName)
        {
            using (FileStream fs = new FileStream(fileName, FileMode.Open))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                return (ImageDate)formatter.Deserialize(fs);
            }
        }
        public ImageDate() { }
        public ImageDate(Bitmap capturedImage, DateTime capturedDateTime)
        {
            CapturedImage = capturedImage;
            CapturedDateTime = capturedDateTime;
        }
    }
于 2019-05-10T22:21:28.010 回答