Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports Microsoft.Kinect
- Public Class Form1
- Dim kinz As KinectSensor
- Dim depthz As DepthImageFrame
- Dim picdepth As Bitmap = New Bitmap(640, 480, Imaging.PixelFormat.Format32bppRgb)
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- For Each potentialSensor In KinectSensor.KinectSensors
- If potentialSensor.Status = KinectStatus.Connected Then
- kinz = potentialSensor
- Exit For
- End If
- Next potentialSensor
- kinz.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30)
- AddHandler kinz.DepthFrameReady, AddressOf depthready
- kinz.Start()
- End Sub
- Private Sub depthready(ByVal sender As Object, ByVal e As DepthImageFrameReadyEventArgs)
- depthz = e.OpenDepthImageFrame
- End Sub
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- depthmethod()
- PictureBox1.Image = picdepth
- End Sub
- 'Color for depth
- Public Sub depthmethod()
- Dim pixz(kinz.DepthStream.FramePixelDataLength - 1) As Short
- Dim pixmax As Integer = 32760
- If depthz IsNot Nothing Then
- depthz.CopyPixelDataTo(pixz)
- Dim rect As New Rectangle(0, 0, picdepth.Width, picdepth.Height)
- Dim bmpData As System.Drawing.Imaging.BitmapData = picdepth.LockBits(rect, _
- Drawing.Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format32bppRgb)
- Dim ptr As IntPtr = bmpData.Scan0
- Dim bytes As Integer = bmpData.Stride * picdepth.Height
- Dim rgbValues(bytes - 1) As Byte
- System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes)
- Dim secondcounter As Integer = 0
- Dim tempred As Integer
- Dim tempblue As Integer
- Dim tempgreen As Integer
- Dim tempalpha As Integer
- Dim range As Integer
- While secondcounter < rgbValues.Length
- tempblue = rgbValues(secondcounter)
- tempgreen = rgbValues(secondcounter + 1)
- tempred = rgbValues(secondcounter + 2)
- tempalpha = rgbValues(secondcounter + 3)
- tempalpha = 255
- If pixz(secondcounter / 4) <> -8 Then
- tempgreen = 255 - ((pixz(secondcounter / 4) / pixmax) * 255)
- Else
- tempgreen = 0
- End If
- tempred = 0
- tempblue = 0
- rgbValues(secondcounter) = tempblue
- rgbValues(secondcounter + 1) = tempgreen
- rgbValues(secondcounter + 2) = tempred
- rgbValues(secondcounter + 3) = tempalpha
- secondcounter = secondcounter + 4
- End While
- System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes)
- picdepth.UnlockBits(bmpData)
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement