-1

I'm doing a license plate recognition system. I have set up my camera to capture image every 10 seconds and stored it in a folder. May I know how to get or capture the date and time and show it in a label for every image captured in the folder. I'm using a C# to code and and also using my usb camera to capture the image

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

    }

I expect by the time it captures the image, it will automatically show on the label the date and time of the image captured.

Yonce
  • 25
  • 5
  • You mean add a label to your form and set it to the current date and time when the image is taken? – stuartd May 10 '19 at 20:18
  • yeah something like that. When the image is captured, the label will show the current date and time of the image captured. This process will be done repeatedly for every image captured at that time @stuartd – Yonce May 10 '19 at 20:22
  • `DateTime.Now`... –  May 10 '19 at 20:25
  • If you want to get the last time the image file was modified, you can use `File.GetLastWriteTime(filePath)` – Rufus L May 10 '19 at 20:28
  • You could also draw the current date/time on the image itself. – Lionize May 10 '19 at 20:55
  • The thing is later i have to store it in a database. – Yonce May 10 '19 at 21:02

1 Answers1

0

You could write a serializable object and save/load that to/from a file.

    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;
        }
    }
Lionize
  • 51
  • 3