Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data
- Imports System.Data.SqlClient
- Imports Accord.Vision.Detection
- Imports Accord.Vision.Detection.Cascades
- Imports Emgu.CV
- Imports Emgu.CV.Structure
- Imports Emgu.CV.Util
- Imports Emgu.CV.CvEnum
- Imports AForge.Video
- Imports System.Drawing.Imaging
- Public Class TestingForm
- Dim tmpgambar(2) As Bitmap
- Dim jumlahCoba As Integer
- Dim imgFrame As Image(Of Bgr, Byte)
- Dim vidCapture As Capture
- Dim imgGray As Image(Of Gray, Byte)
- Public Sub AppIdle(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Try
- imgFrame = vidCapture.QueryFrame.Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC)
- PictureBox1.Image = imgFrame.Bitmap ' this is where captured image go.
- Dim detector As HaarObjectDetector
- Dim cascade As New FaceHaarCascade
- ' Dim cascade As New NoseHaarCascade
- detector = New HaarObjectDetector(cascade, 30)
- detector.SearchMode = ObjectDetectorSearchMode.Average
- detector.ScalingFactor = 1.5
- detector.ScalingMode = ObjectDetectorScalingMode.GreaterToSmaller
- detector.UseParallelProcessing = True
- detector.Suppression = 3
- ' Dim sw As Stopwatch = Stopwatch.StartNew
- Dim faceObjects As Rectangle() = detector.ProcessFrame(PictureBox1.Image)
- ' sw.Stop()
- Dim g As Graphics = Graphics.FromImage(PictureBox1.Image)
- ''Dim pena As New Pen(Brushes.DarkOliveGreen, 10)
- For Each face In faceObjects
- Dim CropImage = New Bitmap(face.Width, face.Height)
- Using grp = Graphics.FromImage(CropImage)
- grp.DrawImage(PictureBox1.Image, New Rectangle(0, 0, face.Width, face.Height), face, GraphicsUnit.Pixel)
- End Using
- ' PictureBox2.Image = CropImage
- g.DrawRectangle(Pens.Red, face)
- Me.ImageList1.Images.Add(CropImage)
- If Me.ImageList1.Images.Count <= 3 Then
- Dim p As New PictureBox
- p.Image = Me.ImageList1.Images(Me.ImageList1.Images.Count - 1)
- p.Image.Save(My.Application.Info.DirectoryPath & "\hasil\Capture" & (My.Settings.Jumlahcapture + 1).ToString("000") & ".bmp")
- My.Settings.Jumlahcapture += 1
- My.Settings.Save()
- waktu = Now
- cekLogin()
- Else
- Me.ImageList1.Images.Clear()
- vidCapture.Dispose()
- Me.PictureBox1.Image = Nothing
- RemoveHandler Application.Idle, AddressOf AppIdle
- End If
- Next
- g.Dispose()
- Me.PictureBox1.Invalidate()
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- End Try
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- Button3.Enabled = True
- jumlahCoba = 0
- Dim koneksi As New SqlClient.SqlConnection(My.Settings.koneksiString)
- koneksi.Open()
- Dim dt As New DataTable
- Dim da As New SqlClient.SqlDataAdapter("SELECT * FROM Pengguna WHERE username='" & Me.usernameTextBox.Text & "' AND PASSWORD='" & Me.passwordTextBox.Text & "'", koneksi)
- da.Fill(dt)
- If dt.Rows.Count > 0 Then
- Dim dr As DataRow = dt.Rows(0)
- Me.GroupBox1.Visible = False
- Me.GroupBox2.Visible = True
- Me.LinkLabel1.Visible = False
- tipePengguna = dr("tipe").ToString
- For i As Integer = 0 To tmpgambar.Length - 1
- tmpgambar(i) = Konvert(CType(dr("sample" & i + 1), Byte()))
- Next
- Else
- MessageBox.Show("Invalid Username and Password")
- End If
- End Sub
- Public Sub CheckStartup()
- Dim Reg = CreateObject("WScript.Shell")
- Try
- Reg.Regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & My.Application.Info.AssemblyName) = Application.ExecutablePath
- Catch ex As Exception
- Reg.RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & My.Application.Info.AssemblyName, Application.ExecutablePath)
- End Try
- End Sub
- Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
- If MessageBox.Show("Apakah Anda Yakin Shutdown PC/Laptop ? ", "Peringatan !!", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
- powerutility("s")
- End If
- End Sub
- Private Sub TestingForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Me.Opacity = 0
- Me.Hide()
- Dim spalas As New SplashForm
- spalas.ShowDialog()
- spalas.Dispose()
- spalas = Nothing
- Me.Opacity = 100
- Timer1.Start()
- Dim koneksi As New SqlClient.SqlConnection(My.Settings.koneksiString)
- koneksi.Open()
- Dim dt As New DataTable
- Dim da As New SqlClient.SqlDataAdapter("SELECT * FROM Pengguna", koneksi)
- da.Fill(dt)
- If dt.Rows.Count < 1 Then
- tipePengguna = "admin"
- Dim input As New InputForm
- input.ShowDialog()
- Else
- tipePengguna = "user"
- Me.Show()
- End If
- End Sub
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- Me.Label5.Text = Me.Label5.Text.Substring(1) & Me.Label5.Text.Substring(0, 1)
- End Sub
- Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
- Me.GroupBox2.Visible = False
- Me.GroupBox1.Visible = True
- End Sub
- Private Sub cekLogin()
- Dim query As String = "INSERT INTO Hasil Values (@nama,@waktu,@ket)"
- Dim koneksi As New SqlClient.SqlConnection(My.Settings.koneksiString)
- koneksi.Open()
- Dim jarak As New List(Of Double)
- Dim PCA As New PCAClass
- Dim input(,) As Double = gambar.GetGrayScale(ImageList1.Images(Me.ImageList1.Images.Count - 1))
- input = PCA.TestingInput(input)
- Dim nomor As Integer = 1
- Dim rata As Double = 0
- For Each d(,) As Double In PCA.Rekonstruksi
- Dim gbr As New Bitmap(d.GetLength(0), d.GetLength(1))
- For i As Integer = 0 To d.GetLength(0) - 1
- For j As Integer = 0 To d.GetLength(1) - 1
- Dim nilai As Integer = 0
- If Math.Abs(Math.Floor(d(i, j))) > 255 Then
- nilai = 255
- Else
- nilai = Math.Abs(Math.Floor(d(i, j)))
- End If
- gbr.SetPixel(j, i, Color.FromArgb(nilai, nilai, nilai))
- Next
- Next
- Try
- Dim pic As New PictureBox
- pic.Image = gbr
- pic.Image.Save(My.Application.Info.DirectoryPath & "\hasil" & nomor & ".bmp")
- Catch ex As Exception
- End Try
- jarak.Add(PCA.Ecludiance(input, d))
- nomor += 1
- rata += jarak.Item(jarak.Count - 1)
- Next
- rata = rata / jarak.Count
- Dim total As Double = 0
- For Each n As Double In jarak
- total += Math.Pow(n - rata, 2)
- Next
- total = Math.Sqrt(total / jarak.Count)
- Dim nilaiambang = rata + total
- Dim tm() As Double = jarak.ToArray
- Dim rendah, posisi As Integer
- For i As Integer = 0 To jarak.Count - 1
- If i = 0 Then
- rendah = tm(i)
- posisi = 1
- ElseIf tm(i) < rendah Then
- rendah = tm(i)
- posisi = i + 1
- End If
- Next
- Dim tmptest As New Bitmap(My.Application.Info.DirectoryPath & "\hasil" & posisi & ".bmp")
- Dim status As Boolean = False
- For Each t As Bitmap In tmpgambar
- Dim n As Double = PCA.Ecludiance(gambar.GetGrayScale(t), gambar.GetPictArray(tmptest))
- If n <= 400 Then
- status = True
- End If
- Next
- Me.Label3.Visible = True
- If status Then
- Dim span As TimeSpan = Now.Subtract(waktu)
- Me.Label3.Text = "Waktu Eksekusi : " & span.Hours.ToString("00") & ":" & span.Minutes.ToString("00") & " : " & span.Seconds.ToString("00") & ":" & span.Milliseconds.ToString("000")
- Try
- Dim da As New SqlClient.SqlDataAdapter(query, koneksi)
- da.SelectCommand.Parameters.AddWithValue("@nama", usernameTextBox.Text)
- da.SelectCommand.Parameters.AddWithValue("@waktu", span.Hours.ToString("00") & ":" & span.Minutes.ToString("00") & ":" & span.Seconds.ToString("00") & ":" & span.Milliseconds.ToString("000"))
- da.SelectCommand.Parameters.AddWithValue("@ket", "Berhasil")
- da.SelectCommand.ExecuteNonQuery()
- Catch ex As Exception
- End Try
- MessageBox.Show("Dikenali")
- Try
- vidCapture.Dispose()
- RemoveHandler Application.Idle, AddressOf AppIdle
- Catch ex As Exception
- End Try
- Me.Hide()
- If tipePengguna.ToLower.Equals("admin") Then
- Dim admin As New MainForm
- admin.ShowDialog()
- Else
- Dim view As New viewpenggunaForm
- view.loadData(Me.usernameTextBox.Text)
- view.ShowDialog()
- End If
- Me.Visible = False
- Else
- Dim span As TimeSpan = Now.Subtract(waktu)
- Me.Label3.Text = "Waktu Eksekusi : " & span.Hours.ToString("00") & ":" & span.Minutes.ToString("00") & " : " & span.Seconds.ToString("00") & " : " & span.Milliseconds.ToString("000")
- Try
- Dim da As New SqlClient.SqlDataAdapter(query, koneksi)
- da.SelectCommand.Parameters.AddWithValue("@nama", usernameTextBox.Text)
- da.SelectCommand.Parameters.AddWithValue("@waktu", span.Hours.ToString("00") & ":" & span.Minutes.ToString("00") & ":" & span.Seconds.ToString("00") & ":" & span.Milliseconds.ToString("000"))
- da.SelectCommand.Parameters.AddWithValue("@ket", "Gagal")
- da.SelectCommand.ExecuteNonQuery()
- Catch ex As Exception
- End Try
- MessageBox.Show("Tidak Dikenali")
- jumlahCoba += 1
- If jumlahCoba >= 3 Then
- Me.GroupBox2.Visible = False
- Me.Label2.Visible = True
- Me.Button4.Visible = True
- Me.Button7.Visible = True
- Me.PictureBox1.Image = Nothing
- End If
- End If
- Me.Label3.Visible = False
- End Sub
- Dim waktu As DateTime
- Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
- If Me.Button3.Text.ToLower.Equals("start") Then
- Try
- jumlahCoba = 0
- vidCapture = New Capture() ' Put the proper arguments in here
- vidCapture.QueryFrame()
- AddHandler Application.Idle, AddressOf AppIdle
- Me.Button3.Enabled = False
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- End Try
- ElseIf Me.Button3.Text.ToLower.Equals("load") Then
- Dim op As New OpenFileDialog
- op.InitialDirectory = My.Application.Info.DirectoryPath & "\gambar"
- If op.ShowDialog() = Windows.Forms.DialogResult.OK Then
- Me.PictureBox1.Image = Image.FromFile(op.FileName)
- Me.ImageList1.Images.Add(Image.FromFile(op.FileName))
- Me.Button3.Text = "Cek"
- End If
- Else
- waktu = Now
- cekLogin()
- End If
- End Sub
- Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
- Me.Label2.Visible = False
- Me.Button4.Visible = False
- Me.Button7.Visible = False
- Me.GroupBox1.Visible = True
- End Sub
- Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
- If MessageBox.Show("Apakah Anda Yakin Shutdown PC/Laptop ? ", "Peringatan !!", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
- powerutility("s")
- End If
- End Sub
- Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
- End Sub
- Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
- Button3.Text = "Start"
- End Sub
- Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
- Button3.Text = "Load"
- End Sub
- Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
- 'Me.Hide()
- Dim about As New aboutForm
- about.ShowDialog()
- about.Dispose()
- about = Nothing
- Me.Show()
- End Sub
- Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
- End Sub
- Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement