save pictures from Webcam using EMGU

792 Views Asked by At

I want to modify my program in VB 2015 that captures a photo using a webcam and saves it to my folder. The problem is that it replaces every picture taken, I want to save every picture with this format name picture01, picture02 etc.

Info: I am using Emgu.

picture

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Try
      PictureBox1.Image = capture.QueryFrame.ToBitmap()
    Catch ex As Exception
      capture = New Emgu.CV.Capture
    End Try
End Sub


Private Sub startWebcam_Click(sender As Object, e As EventArgs) Handles startWebcam.Click
    Timer1.Start()
End Sub

Private Sub captWebcam_Click(sender As Object, e As EventArgs) Handles captWebcam.Click
    Dim picnumber As Integer = 0
    Timer1.Stop()
    'Save the picture
    PictureBox1.Image.Save("D:\WEBCAM\Img01.JPEG", Imaging.ImageFormat.Jpeg)
    capture.Dispose()
End Sub
2

There are 2 best solutions below

1
NewOldDude On

You could make your file name a date stamp, that way it will always be unique:

Dim a As String = Now.ToShortDateString & Now.ToLongTimeString
a = a.Replace(":", "").Replace("/", "").Replace("\", "")

PictureBox1.Image.Save("D:\WEBCAM\" & a & ".JPEG", Imaging.ImageFormat.Jpeg)
0
Stephen On

You could also use a simple integer increment:

Private FileID as Integer = 0
Private Sub captWebcam_Click(sender As Object, e As EventArgs) Handles captWebcam.Click
    Timer1.Stop()

    'Save the picture
    FileID += 1
    PictureBox1.Image.Save("D:\WEBCAM\Img" & FileID.ToString("00") & ".JPEG", Imaging.ImageFormat.Jpeg)
    capture.Dispose()
End Sub