Logo
Acquisti Giochi Scienza Affari Notizie Societè Casa
Regionale Sport Computer Salute Tempo libero Consultazione  


TrafficSignRecognition

' translated in VB:NET from c#

' by Giuseppe Di Santo - Studio IT

 

Imports System.Collections.Generic

Imports System.ComponentModel

Imports System.Data

Imports System.Drawing

Imports System.Text

Imports System.Windows.Forms

Imports Emgu.CV

Imports Emgu.CV.Structure

Imports Emgu.CV.UI

Imports System.Diagnostics

 

Public Class TrafficSignRecognition

 

    Private _stopSignDetector As StopSignDetector

 

 

 

    Private Sub TrafficSignRecognition_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        _stopSignDetector = New StopSignDetector()

 

        ProcessImage(New Image(Of Bgr, Byte)("stop-sign.jpg"))

    End Sub

 

 

    Private Sub ProcessImage(ByVal image As Image(Of Bgr, Byte))

 

        Dim watch As Stopwatch = Stopwatch.StartNew()

 

        ' time the detection process

        Dim stopSignList As List(Of Image(Of Gray, [Byte])) = New List(Of Image(Of Gray, Byte))()

        Dim stopSignBoxList As New List(Of Rectangle)()

        _stopSignDetector.DetectStopSign(image, stopSignList, stopSignBoxList)

 

        watch.[Stop]()

        'stop the timer

        processTimeLabel.Text = [String].Format("Stop Sign Detection time: {0} milli-seconds", watch.Elapsed.TotalMilliseconds)

 

        panel1.Controls.Clear()

        Dim startPoint As New Point(10, 10)

 

        For i As Integer = 0 To stopSignList.Count - 1

            Dim rect As Rectangle = stopSignBoxList(i)

            AddLabelAndImage(startPoint, [String].Format("Stop Sign [{0},{1}]:", rect.Location.Y + rect.Width / 2, rect.Location.Y + rect.Height / 2), stopSignList(i))

            image.Draw(rect, New Bgr(Color.Aquamarine), 2)

        Next

 

        imageBox1.Image = image

 

    End Sub

 

    Private Sub AddLabelAndImage(ByRef startPoint As Point, ByVal labelText As [String], ByVal image As IImage)

        Dim label As New Label()

        panel1.Controls.Add(label)

        label.Text = labelText

        label.Width = 100

        label.Height = 30

        label.Location = startPoint

        startPoint.Y += label.Height

 

        Dim box As New ImageBox()

        panel1.Controls.Add(box)

        box.ClientSize = image.Size

        box.Image = image

        box.Location = startPoint

        startPoint.Y += box.Height + 10

    End Sub

 

    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim result As DialogResult = openFileDialog1.ShowDialog()

        If result = DialogResult.OK Then

            Dim img As Image(Of Bgr, [Byte])

            Try

                img = New Image(Of Bgr, Byte)(openFileDialog1.FileName)

            Catch

                MessageBox.Show("Invalide file format")

                Return

            End Try

 

            ProcessImage(img)

        End If

    End Sub

 

 

 

End Class

 

<< back to index