【问题标题】:How to get date for every image captured in folder using C#如何使用 C# 获取文件夹中捕获的每个图像的日期
【发布时间】:2019-09-28 18:10:10
【问题描述】:

我正在做一个车牌识别系统。我已将相机设置为每 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++;
        }

    }

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

【问题讨论】:

  • 您的意思是在表单中添加标签并将其设置为拍摄图像的当前日期和时间?
  • 是的,类似的。拍摄图像时,标签将显示拍摄图像的当前日期和时间。这个过程将针对当时捕获的每张图像重复执行@stuartd
  • DateTime.Now...
  • 如果想获取上次修改图片文件的时间,可以使用File.GetLastWriteTime(filePath)
  • 您还可以在图像本身上绘制当前日期/时间。

标签: c# visual-studio-2013 camera image-capture alpr


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-15
    • 2016-06-25
    相关资源
    最近更新 更多