Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6660243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:07:51+00:00 2026-05-26T02:07:51+00:00

I am using the kinect to do a few things in F# but am

  • 0

I am using the kinect to do a few things in F# but am having a little trouble working with depth data. I have been following this tutorial: http://digitalerr0r.wordpress.com/2011/06/21/kinect-fundamentals-3-getting-data-from-the-depth-sensor/

which has c# examples which I have been trying to convert to F#.

This part of code is being problematic:

void kinectSensor_DepthFrameReady(object sender, ImageFrameReadyEventArgs e)
{
PlanarImage p = e.ImageFrame.Image;

    Color[] DepthColor = new Color[p.Height * p.Width];

    float maxDist = 4000;
    float minDist = 850;
    float distOffset = maxDist – minDist;

    kinectDepthVideo = new Texture2D(GraphicsDevice, p.Width, p.Height);

    int index = 0;
    for (int y = 0; y < p.Height; y++)
    {
        for (int x = 0; x < p.Width; x++, index += 2)
        {
            int n = (y * p.Width + x) * 2;
            int distance = (p.Bits[n + 0]  |  p.Bits[n + 1] << 8);
            byte intensity = (byte)(255 – (255 * Math.Max(distance – minDist, 0) / (distOffset)));
            DepthColor[y * p.Width + x] = new Color(intensity, intensity, intensity);

        }
    }
}

The problem I am having appears to be with this part: int distance = (p.Bits[n + 0] | p.Bits[n + 1] << 8);

in F# his should become let distance = (p.Bits.[n+0] ||| p.Bits.[n+1] <<< 8)

this means, through type inferance that distance is of type “byte” which I then cast to an int like this: let distance = int(p.Bits.[n+0] ||| p.Bits.[n+1] <<< 8). is this the correct way to convert a bit to an int? Are my bitwise operations correct? As I have been learning F# from scratch myself I am unsure but this doesnt throw any syntax errors.

However, it does mean that all my depth measurements come out as 0. If I have it as byte they are slightly more sensible but they dont work with the next line (this one is in c# but I do have an F# version of it… does the same thing!)byte intensity = (byte)(255 – (255 * Math.Max(distance – minDist, 0) / (distOffset)));

Essentially I cannot get it to do anything other than give me 255 for each output intensity.

Any help would be really appreciated and apologies for the obscure things I am trying to do! Should probably just use C#!

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:07:52+00:00Added an answer on May 26, 2026 at 2:07 am

    The snippet below shows that conversion from two adjacent bytes of array into int works right:

    let bytes = [|1uy;1uy|]
    let distance = int bytes.[0] ||| (int bytes.[1] <<< 8)
    printfn "%08X" distance
    00000101
    val bytes : byte [] = [|1uy; 1uy|]
    val distance : int = 257
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're doing an augmented reality application using the kinect. This has some challenges: We'll
I just got a Kinect and I have it connected to the computer using
I have a project dealing with video conferencing using the Kinect (or, more likely,
We've been working on a digital drawing system using XNA for display and using
I'm using the Microsoft Kinect SDK to get the depth and color information from
I'm currently using a Processing Kinect library which supplies a depth map. I was
I've written a program that uses the Depth data from a Kinect, and does
I am trying to get audio using Kinect's microphones, but can't even even get
I have a byte[] I captured from Kinect using OpenKinect and it's Java JNA
I want to develop a gesture recognition. I'm considering using the Kinect to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.