Sie sind auf Seite 1von 4

Imports Emgu.CV Imports Emgu.CV.Structure Imports Emgu.

Util Public Class Form1 Dim camState As Boolean = False Dim imgColor As New Image(Of Bgr, Byte)(320, 240) Dim imgGray As New Image(Of Gray, Byte)(320, 240) Dim face As New HaarCascade("FrontalFace.xml") Dim eye As New HaarCascade("Eye.xml") Dim nose As New HaarCascade("Nose.xml") Dim Dim Dim Dim faceDetected As MCvAvgComp() eyeDetected As MCvAvgComp() noseDetected As MCvAvgComp() cap As New Capture(0)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If camState = False Then cap.SetCaptureProperty(CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WI DTH, 320) cap.SetCaptureProperty(CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HE IGHT, 240) Button1.Text = "Stop" camState = True Timer1.Enabled = True Else Button1.Text = "Start" camState = False Timer1.Enabled = False End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim cHeadX, cEyeX, cNoseX As Integer imgColor = cap.QueryFrame imgGray = imgColor.Convert(Of Gray, Byte)() imgGray._EqualizeHist() faceDetected = imgGray.DetectHaarCascade(face, 1.1, 3, _ CvEnum.HAAR_DETECTION_TYPE.FIND_BIGGEST_OBJECT, New Size(10, 10))(0) For Each fo In faceDetected cHeadX = fo.rect.X + fo.rect.Width / 2 imgColor.Draw(fo.rect, New Bgr(Color.Red), 1) imgGray.ROI = fo.rect eyeDetected = imgGray.DetectHaarCascade(eye, 1.1, 3, _ CvEnum.HAAR_DETECTION_TYPE.FIND_BIGGEST_OBJECT, New Size(10, 10))(0) For Each eo In eyeDetected eo.rect.Offset(fo.rect.X, fo.rect.Y) cEyeX = eo.rect.X + eo.rect.Width / 2

imgColor.Draw(eo.rect, New Bgr(Color.Green), 1) Next noseDetected = imgGray.DetectHaarCascade(nose, 1.1, 3, _ CvEnum.HAAR_DETECTION_TYPE.FIND_BIGGEST_OBJECT, New Size(10, 10))(0) For Each no In noseDetected no.rect.Offset(fo.rect.X, fo.rect.Y) cNoseX = no.rect.X + no.rect.Width / 2 imgColor.Draw(no.rect, New Bgr(Color.Green), 1) Next imgGray.ROI = Rectangle.Empty Next Label1.Text = "Center of Head,Eye,Nose =" + CStr(cHeadX) + "," + CStr(cEyeX) + "," + CStr(cNoseX) ImageBox1.Image = imgColor End Sub End Class

Imports Imports Imports Imports Imports

Microsoft.DirectX Microsoft.DirectX.Direct3D Emgu.CV Emgu.CV.Structure Emgu.Util

Public Class Form1 Private device As Direct3D.Device Private vertex As CustomVertex.PositionColored() Dim angle As Double Dim x, y, z As Single Dim sp As Mesh Dim sudut As Double Dim camState As Boolean = False Dim imgColor As New Image(Of Bgr, Byte)(220, 140) Dim imgGray As New Image(Of Gray, Byte)(220, 140) Dim face As New HaarCascade("FrontalFace.xml") Dim eye As New HaarCascade("Eye.xml") Dim nose As New HaarCascade("Nose.xml") Dim Dim Dim Dim faceDetected As MCvAvgComp() eyeDetected As MCvAvgComp() noseDetected As MCvAvgComp() cap As New Capture(0)

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

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Drawscene() End Sub Private Sub Initscene() InitWindow() InitDevice() InitCamera() InitRenderState() 'InitVertex() InitMesh() End Sub Private Sub InitWindow() Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True) Me.Height = 500 Me.Width = 500 Me.Text = "Computer Graphics Programming" End Sub Private Sub InitDevice() Dim Present As PresentParameters = New PresentParameters Present.Windowed = True Present.SwapEffect = SwapEffect.Discard device = New Direct3D.Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, Present) End Sub Private Sub InitCamera() device.Transform.Projection = Matrix.PerspectiveFovRH(CSng(Math.PI / 4.0), Me.Width / Me.Height, 1.0F, 50.0F) device.Transform.View = Matrix.LookAtRH(New Vector3(0.0F, 0.0F, 5.0F), New Vector3(0.0F, 0.0F, 0.0F), New Vector3(0.0F, 1.0F, 0.0F)) End Sub Private Sub InitRenderState() device.RenderState.Lighting = False device.RenderState.CullMode = Cull.None device.RenderState.FillMode = FillMode.WireFrame End Sub Private Sub InitVertex() vertex = New CustomVertex.PositionColored(2) {} vertex(0).Position = New Vector3(0.0F, 0.0F, 0.0F) vertex(0).Color = Color.Red.ToArgb vertex(1).Position = New Vector3(10.0F, 0.0F, 0.0F) vertex(1).Color = Color.Green.ToArgb vertex(2).Position = New Vector3(5.0F, 10.0F, 0.0F) vertex(2).Color = Color.Blue.ToArgb End Sub Private Sub InitMesh() 'sp = Mesh.Teapot(device) 'sp = Mesh.Sphere(device, 5.0F, 15, 15) sp = Mesh.FromFile("tiger.x", MeshFlags.SystemMemory, device) End Sub Private Sub Drawscene() Dim i, numbSubsets, As Integer device.Clear(ClearFlags.Target, Color.Black, 1.0F, 0)

device.BeginScene() 'device.VertexFormat = CustomVertex.PositionColored.Format '//BENDA KERJA YANG BERPUTAR VIEW KAMERA TETAP 'device.Transform.World = Matrix.RotationZ(angle) * Matrix.Translation(5.0F, 0.0F, 0.0F) 'geser muter 'device.Transform.World = Matrix.Translation(5.0F, 0.0F, 0.0F) * Matrix.RotationZ(angle) 'muter geser ' angle = angle + 0.05F '//KAMERA YANG DIPUTAR DAN BENDA KERJA DIAM ' device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,

vertex)

'device.Transform.View = Matrix.LookAtRH(New Vector3(x, y, z), New Vector3(0.0F, 0.0F, 0.0F), New Vector3(0.0F, 0.1F, 0.0F)) 'angle = angle + 0.05F 'z = 30.0 * Math.Sin(angle) 'x = 30.0 * Math.Cos(angle) 'y = 0.0F '/........................ '//pake mesh, ga pake vertex >> yang pake vertex2 dinonaktivkan numbSubsets = sp.GetAttributeTable().Length For i = 0 To numbSubsets sp.DrawSubset(i) Next device.Transform.View = Matrix.LookAtRH(New Vector3(x, y, z), New Vector3(0.0F, 0.0F, 0.0F), New Vector3(0.0F, 0.1F, 0.0F)) angle = angle + 0.05F 'z = 5 * Math.Sin(angle) 'x = 5 * Math.Cos(angle) z = 5 * Math.Sin(sudut) x = 5 * Math.Cos(sudut) y = 0.0F '----------------------------------device.EndScene() device.Present() Me.Invalidate() End Sub

Das könnte Ihnen auch gefallen