microsoft / psi

Platform for Situated Intelligence
https://github.com/microsoft/psi/wiki
Other
534 stars 94 forks source link

RealSense example #156

Open profwillie opened 3 years ago

profwillie commented 3 years ago

Is there a working example of the RealSense psi component? I know that @kahlilfitz has an example, but that example creates a new component, and I'm hoping to use the component here: https://github.com/microsoft/psi/tree/master/Sources/RealSense

One problem I am having to start: Is the code available in a nuget? Or do I need to use the source for this?

sandrist commented 3 years ago

Hi Willie, unfortunately we are not able to generate a nuget for that one, because we can't redistribute the RealSense SDK that it depends on. To use that component, you'll need to build the project from source. Thankfully, in addition to the native Microsoft.Psi.RealSense_Interop.Windows.x64 project, it only depends on Microsoft.Psi and Microsoft.Psi.Imaging. In addition, you'll need to separately download the RealSense SDK somewhere, and create an environment variable on your machine called "RealSenseSDKDir" that points to it.

trigaten commented 3 years ago

@profwillie Here is a working code example (assuming you have a correct build config): It is directly adapted from the first part of the Kinect example with only a few changes.

Imports:

using System;
using Microsoft.Psi;
using Microsoft.Psi.RealSense.Windows;
using System.Text;
using Microsoft.Psi.Imaging;

Main:

            RealSenseSensor r = new(p);
            const int widthOutput = 160;
            const int heightOutput = 90;

            StringBuilder sb = new StringBuilder();
            r.ColorImage.Resize(widthOutput, heightOutput).Do(color =>
            {
                var bitmap = color.Resource.ToBitmap();

                // render color frame as "ASCII art"
                sb.Clear();
                for (int y = 0; y < heightOutput; y += 2)
                {
                    for (int x = 0; x < widthOutput; x++)
                    {
                        var p = bitmap.GetPixel(x, y);
                        sb.Append(" .:-=+*#%@"[(int)((p.R + p.G + p.B) / 76.5)]);
                    }

                    sb.Append(Environment.NewLine);
                }

                Console.SetCursorPosition(0, 0);
                Console.WriteLine(sb.ToString());
            });

            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;
            Console.Clear();
            p.RunAsync();
            Console.ReadLine();