我正在做一个车牌识别系统。我已经将相机设置为每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++;
}
}
我希望它在捕获图像时会自动在标签上显示捕获图像的日期和时间。
答案 0 :(得分: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;
}
}