none
Kinect Explorer in VB.NET?

    Question

  • Hello,

    I am getting started with Kinect for Windows SDK (latest version) using VB.NET and do really need some good adivce from VB.NET code samples. The kinext explorer does only provide C# code samples. Where can I find the kinect explorer source code in VB.NET?

    If the kinect explorer doesn't exist in VB.NET: When is it going to be published?

    Wednesday, March 14, 2012 2:03 PM

Answers

All replies

  • I used c# enough I could convert for you and if you have visual studio instead of express editions of vb.net you can code xna xbox games in vb.net now.

    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda

    Wednesday, March 14, 2012 2:21 PM
  • So, could you please convert it completely?!?
    Wednesday, March 14, 2012 2:50 PM
  • If your looking for vb.net samples for the kinect though and was trying to use kinect explorer try out the kinectcontrib.codeplex.com webpage go to downloads  section and download the installer for the kinect sdk v1 commerical templates I use them when troublshooting something because they give me the maximum frame rate and are very simple (Plus in VB.NET!). It would take me two or three days to fully convert the code but Im writing my projects for kinect all in vb.net on codeplex if you need more samples that involve multiple players.

    heres the list of my projects:

    http://kinectmultipoint.codeplex.com - get kinect to work with mouse mischief/microsofts multipoint mouse sdk (not multipoint server)

    http://kinectsignlanguage.codeplex.com - still a work in progress but i will eventually have a sign language program made for the kinect that will interpret the signers sign language and speak the word. For instance, sign the letter a and the computer will speak A.

    In addition, I forgot kinectmouse.codeplex.com's project page has c# and vb.net samples so you can see the difference if your wondering.


    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda



    • Edited by The Thinker Wednesday, March 14, 2012 3:13 PM
    Wednesday, March 14, 2012 3:08 PM
  • Thanks for your reply. I will check the source code and will surely learn a lot of it.

    I have a certain problem, maybe, you might help me. I try to translate this code snippet from class KinectDepthViewer.xaml.cs of the Kinect Explorer sample to VB.NET:

            private byte[] ConvertDepthFrame(short[] depthFrame, DepthImageStream depthStream)
            {
                int tooNearDepth = depthStream.TooNearDepth;
                int tooFarDepth = depthStream.TooFarDepth;
                int unknownDepth = depthStream.UnknownDepth;
    
                for (int i16 = 0, i32 = 0; i16 < depthFrame.Length && i32 < this.depthFrame32.Length; i16++, i32 += 4)
                {
                    int player = depthFrame[i16] & DepthImageFrame.PlayerIndexBitmask;
                    int realDepth = depthFrame[i16] >> DepthImageFrame.PlayerIndexBitmaskWidth;
                    
                    // transform 13-bit depth information into an 8-bit intensity appropriate
                    // for display (we disregard information in most significant bit)
                    byte intensity = (byte)(~(realDepth >> 4));
    
                    if (player == 0 && realDepth == 0)
                    {
                        // white 
                        this.depthFrame32[i32 + RedIndex] = 255;
                        this.depthFrame32[i32 + GreenIndex] = 255;
                        this.depthFrame32[i32 + BlueIndex] = 255;
                    }
                    else if (player == 0 && realDepth == tooFarDepth)
                    {
                        // dark purple
                        this.depthFrame32[i32 + RedIndex] = 66;
                        this.depthFrame32[i32 + GreenIndex] = 0;
                        this.depthFrame32[i32 + BlueIndex] = 66;
                    }
                    else if (player == 0 && realDepth == unknownDepth)
                    {
                        // dark brown
                        this.depthFrame32[i32 + RedIndex] = 66;
                        this.depthFrame32[i32 + GreenIndex] = 66;
                        this.depthFrame32[i32 + BlueIndex] = 33;
                    }
                    else
                    {
                        // tint the intensity by dividing by per-player values
                        this.depthFrame32[i32 + RedIndex] = (byte)(intensity >> IntensityShiftByPlayerR[player]);
                        this.depthFrame32[i32 + GreenIndex] = (byte)(intensity >> IntensityShiftByPlayerG[player]);
                        this.depthFrame32[i32 + BlueIndex] = (byte)(intensity >> IntensityShiftByPlayerB[player]);
                    }
                }
    
                return this.depthFrame32;
            }
    

    I got translated nearly everything and yet get a depth data stream displayed with using this VB.NET code:

      Private Function ConvertDepthFrame(depthFrame As Short(), depthStream As DepthImageStream) As Byte()
        Dim tooNearDepth As Integer = depthStream.TooNearDepth
        Dim tooFarDepth As Integer = depthStream.TooFarDepth
        Dim unknownDepth As Integer = depthStream.UnknownDepth
    
        Dim i16 As Integer = 0, i32 As Integer = 0
        While i16 < depthFrame.Length AndAlso i32 < Me.depthFrame32.Length
          Dim player As Integer = depthFrame(i16) And DepthImageFrame.PlayerIndexBitmask
          Dim realDepth As Integer = depthFrame(i16) >> DepthImageFrame.PlayerIndexBitmaskWidth
    
          ' transform 13-bit depth information into an 8-bit intensity appropriate
          ' for display (we disregard information in most significant bit)
          'Dim intensity As Byte = CByte(Not (realDepth >> 4)) <<< ERROR
          ' I tried this alternatively:
          'Dim intensity As Byte = CByte(255 - (255 * realDepth / &HFFF)) <<<< App gets stuck
    
          If player = 0 AndAlso realDepth = 0 Then
            ' white 
            Me.depthFrame32(i32 + RedIndex) = 255
            Me.depthFrame32(i32 + GreenIndex) = 255
            Me.depthFrame32(i32 + BlueIndex) = 255
          ElseIf player = 0 AndAlso realDepth = tooFarDepth Then
            ' dark purple
            Me.depthFrame32(i32 + RedIndex) = 66
            Me.depthFrame32(i32 + GreenIndex) = 0
            Me.depthFrame32(i32 + BlueIndex) = 66
          ElseIf player = 0 AndAlso realDepth = unknownDepth Then
            ' dark brown
            Me.depthFrame32(i32 + RedIndex) = 66
            Me.depthFrame32(i32 + GreenIndex) = 66
            Me.depthFrame32(i32 + BlueIndex) = 33
            'Else
            ' tint the intensity by dividing by per-player values
            'Me.depthFrame32(i32 + RedIndex) = CByte(intensity >> IntensityShiftByPlayerR(player))
            'Me.depthFrame32(i32 + GreenIndex) = CByte(intensity >> IntensityShiftByPlayerG(player))
            'Me.depthFrame32(i32 + BlueIndex) = CByte(intensity >> IntensityShiftByPlayerB(player))
          End If
          i16 += 1
          i32 += 4
        End While
    
        Return Me.depthFrame32
    
      End Function
    

    But as you can see, I wasn't able to translate this line of code:

                    // transform 13-bit depth information into an 8-bit intensity appropriate
                    // for display (we disregard information in most significant bit)
                    byte intensity = (byte)(~(realDepth >> 4));
    

    I tried the following, but it doesn't work:

          ' transform 13-bit depth information into an 8-bit intensity appropriate
          ' for display (we disregard information in most significant bit)
          'Dim intensity As Byte = CByte(Not (realDepth >> 4)) <<< ERROR
          ' I tried this alternatively:
          'Dim intensity As Byte = CByte(255 - (255 * realDepth / &HFFF)) <<<< App gets stuck
    

    It would be very helpful to me, if you could try to translate this.
    Wednesday, March 14, 2012 4:00 PM
  • Im not very good at the bit operations can anyone translate the but operations above into vb.net?

    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda

    Wednesday, March 14, 2012 4:09 PM
  • You had it right except for the overflow checking with 'Dim intensity As Byte = CByte(Not (realDepth >> 4)) <<< ERROR.

    Try this:
    Dim intensity As Byte = (Not (realDepth >> 4)) And 255


    (fixed the && to And)

    Friday, March 16, 2012 3:43 AM
    Owner
  • Hello Carmine,

    I will try it tomorrow ... could you explain your code? Currently I deeply dive into binary operations and bit shifting and all that stuff. An explanation would help me a lot.

    Friday, March 16, 2012 4:52 PM
  • Sorry, but the && may have confused you so I fixed that code. Here is the line of code broken down

    Dim realDepth As Short = 19472 'Some value returned from the Kinect byte array
    Dim shift As Short = realDepth >> 4 'gets the most significant bits from the depth data
    Dim mask As Short = Not (shift) 'invert the value, because far is going to be a darker color ~0 for RGB 
    Dim cast As Byte = mask And &HFF 'byte is 255, by using &&/And we mask the upper bits and get the last byte since CByte will throw error

    Friday, March 16, 2012 6:58 PM
    Owner
  • Carmine, thank you very much again. Great explanation.

    One question left: Why does CByte throw an error?

    Tuesday, March 20, 2012 8:19 AM
  • Hello all,

    I opened a small code snippet series about programming Kinect for Windows using VB.NET at my german blog. I hope this is helpful for all the VB'ler out there who start coding Kinect for Windows SDK like I do. Here are the links to the parts of this series published so far:

    Part 1: Displaying Color Image Stream using VB.NET

    Part 2: Displaing the Depth Data Stream using VB.NET

    Carmine, I mentioned your help from this forum thread in part 2; thanks again for your great help!

    Regards,

    Martin

    Tuesday, March 20, 2012 11:04 AM
  • It is a VB.Net option to make this type of casting a "checked" operation. In c# it is not.

    http://msdn.microsoft.com/en-us/library/system.overflowexception.aspx#Y2063

    Tuesday, March 20, 2012 5:42 PM
    Owner