Example #1
0
 private void FrmMainFormClosing(object sender, FormClosingEventArgs e)
 {
     handTracker?.StopGestureDetection(GestureData.GestureType.HandRaise);
     handTracker?.Dispose();
     NiTE.Shutdown();
     OpenNI.Shutdown();
 }
Example #2
0
 public void Dispose()
 {
     foreach (var createdDevice in createdDevices)
     {
         createdDevice.Close();
     }
     OpenNI.Shutdown();
     NiTE.Shutdown();
     GC.SuppressFinalize(this);
 }
Example #3
0
 public static void Initialize()
 {
     OpenNI.Shutdown();//例外などで前回シャットダウンされなかった場合用
     OpenNI.Initialize();
     NiTE.Initialize();
     ConnectedDevices             = OpenNI.EnumerateDevices();
     OpenNI.OnDeviceConnected    += OpenNI_onDeviceConnected;
     OpenNI.OnDeviceDisconnected += OpenNI_onDeviceConnected;
     OpenNI.OnDeviceStateChanged += OpenNI_onDeviceStateChanged;
     Instance = new OpenNIManager();
 }
Example #4
0
        public static void Main(string[] args)
        {
            try
            {
                OpenNI.Initialize();
                device = Device.Open(Device.AnyDevice);

                depthStream           = device.CreateVideoStream(Device.SensorType.Depth);
                depthStream.VideoMode = new VideoMode
                {
                    DataPixelFormat = VideoMode.PixelFormat.Depth1Mm,
                    Fps             = 30,
                    Resolution      = new Size(640, 480)
                };

                colorStream           = device.CreateVideoStream(Device.SensorType.Color);
                colorStream.VideoMode = new VideoMode
                {
                    DataPixelFormat = VideoMode.PixelFormat.Rgb888,
                    Fps             = 30,
                    Resolution      = new Size(640, 480)
                };
                device.DepthColorSyncEnabled = true;
                depthStream.Start();
                colorStream.Start();
                device.ImageRegistration = Device.ImageRegistrationMode.DepthToColor;

                Console.WriteLine("Image registration is active and working well.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();

            if (device != null)
            {
                device.Close();
            }

            OpenNI.Shutdown();
        }
        private void OpenNI2_Terminate()
        {
            if (this.mStream != null && this.mStream.IsValid)
            {
                this.mStream.Stop();
                this.mStream = null;
            }

            if (this.mDevice != null && this.mDevice.IsValid)
            {
                this.mDevice.Close();
                this.bIsDeviceOpened = false;

                this.mDevice.Dispose();
                this.mDevice = null;
            }

            OpenNI.Shutdown();
        }
Example #6
0
        private void frm_Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (this.selectedDevice != null)
                {
                    this.selectedDevice.Close();
                }
            }
            catch (Exception)
            {
            }

            try
            {
                OpenNI.Shutdown();
            }
            catch (Exception)
            {
            }

            Environment.Exit(0);
        }
Example #7
0
 private void FrmMainFormClosed(object sender, FormClosedEventArgs e)
 {
     OpenNI.Shutdown();
     NiTE.Shutdown();
 }
Example #8
0
 private void FrmMainFormClosing(object sender, FormClosingEventArgs e)
 {
     userTracker?.Dispose();
     NiTE.Shutdown();
     OpenNI.Shutdown();
 }
Example #9
0
 private void FrmMainFormClosing(object sender, FormClosingEventArgs e)
 {
     NiTE.Shutdown();
     OpenNI.Shutdown();
 }
Example #10
0
 public void Dispose()
 {
     OpenNI.Shutdown();
 }
Example #11
0
        public static void Main(string[] args)
        {
            var OpenNIPathOnWindows = "%ProgramFiles%\\OpenNI2\\Redist";

            InteropHelper.RegisterLibrariesSearchPath(OpenNIPathOnWindows);

            Console.WriteLine("Runnung in {0}-bit mode.", Environment.Is64BitProcess ? "64" : "32");

            OpenNI.Initialize();

            var version = OpenNI.GetVersion();

            Console.WriteLine("OpenNI version: {0}.{1}.{2}.{3}.", version.Major, version.Minor, version.Maintenance, version.Build);
            Console.WriteLine();

            //OpenNI.SetLogMinSeverity(0);
            //OpenNI.SetLogConsoleOutput(true);
            //OpenNI.SetLogFileOutput(true);
            //Console.WriteLine("Log file path: {0}", OpenNI.GetLogFileName());

            var devices = OpenNI.GetDevices();

            Console.WriteLine("Found {0} device(s):", devices.Length);
            devices.ToList().ForEach(x => Console.WriteLine("{0} from {1} @ {2} with usb id {3}:{4}.", x.Name, x.Vendor, x.Uri, x.UsbVendorId, x.UsbProductId));
            Console.WriteLine();

            if (devices.Length == 0)
            {
                return;
            }

            // open default device
            using (var device = Device.Open())
            {
                var deviceInfo = device.GetDeviceInfo();
                Console.WriteLine("Device {0} @ {1} was successfully opened.", deviceInfo.Name, deviceInfo.Uri);
                Console.WriteLine();

                if (device.IsDriverVersionPropertySupported)
                {
                    var driverVersion = device.DriverVersion;
                    Console.WriteLine("Driver version: {0}.{1}.{2}.{3}.", driverVersion.Major, driverVersion.Minor, driverVersion.Maintenance, driverVersion.Build);
                    Console.WriteLine("Hardware version: {0}.", device.HardwareVersion);
                    Console.WriteLine("Serial number: {0}.", device.SerialNumber);
                    Console.WriteLine();
                }

                var infraredSensorInfo = device.GetSensorInfo(SensorType.Infrared);
                DescribeSensor(infraredSensorInfo);
                Console.WriteLine();

                var colorSensorInfo = device.GetSensorInfo(SensorType.Color);
                DescribeSensor(colorSensorInfo);
                Console.WriteLine();

                var depthSensorInfo = device.GetSensorInfo(SensorType.Depth);
                DescribeSensor(depthSensorInfo);
                Console.WriteLine();

                using (var stream = device.CreateStream(SensorType.Depth))
                {
                    var streamSensorInfo = stream.GetSensorInfo();
                    DescribeVideoModes(streamSensorInfo);
                    Console.WriteLine();

                    stream.VideoMode = new VideoMode {
                        Fps = 30, PixelFormat = PixelFormat.Depth100UM, ResolutionX = 640, ResolutionY = 480
                    };

                    var videoMode = stream.VideoMode;

                    var hFov     = stream.IsHorizontalFovPropertySupported ? stream.HorizontalFov : float.NaN;
                    var vFov     = stream.IsVerticalFovPropertySupported ? stream.VerticalFov : float.NaN;
                    var minValue = stream.IsMinValuePropertySupported ? stream.MinValue : -1;
                    var maxValue = stream.IsMaxValuePropertySupported ? stream.MaxValue : -1;

                    Console.WriteLine("Stream properties:");
                    var rtdK = (float)(180.0 / Math.PI);
                    Console.WriteLine("Horizontal {0:0.0} (deg) and vertical {1:0.0} (deg) FOV.", hFov * rtdK, vFov * rtdK);
                    Console.WriteLine("Min {0} and max {1} values.", minValue, maxValue);

                    stream.Start();

                    for (int i = 0; i < 30; i++)
                    {
                        ReadFreame(stream);
                    }


                    stream.Stop();
                }
            }
            OpenNI.Shutdown();
        }
Example #12
0
        private static void Main()
        {
            Console.WriteLine(OpenNI.Version.ToString());
            OpenNI.Status status = OpenNI.Initialize();
            if (!HandleError(status))
            {
                Environment.Exit(0);
            }

            OpenNI.OnDeviceConnected    += OpenNiOnDeviceConnected;
            OpenNI.OnDeviceDisconnected += OpenNiOnDeviceDisconnected;
            DeviceInfo[] devices = OpenNI.EnumerateDevices();
            if (devices.Length == 0)
            {
                return;
            }

            Device device;

            // lean init and no reset flags
            using (device = Device.Open(null, "lr"))
            {
                if (device.HasSensor(Device.SensorType.Depth) && device.HasSensor(Device.SensorType.Color))
                {
                    VideoStream depthStream = device.CreateVideoStream(Device.SensorType.Depth);
                    VideoStream colorStream = device.CreateVideoStream(Device.SensorType.Color);
                    if (depthStream.IsValid && colorStream.IsValid)
                    {
                        if (!HandleError(depthStream.Start()))
                        {
                            OpenNI.Shutdown();
                            return;
                        }

                        if (!HandleError(colorStream.Start()))
                        {
                            OpenNI.Shutdown();
                            return;
                        }

                        new Thread(DisplayInfo).Start();
                        depthStream.OnNewFrame += DepthStreamOnNewFrame;
                        colorStream.OnNewFrame += ColorStreamOnNewFrame;
                        VideoStream[] array = { depthStream, colorStream };
                        while (!Console.KeyAvailable)
                        {
                            VideoStream aS;
                            if (OpenNI.WaitForAnyStream(array, out aS) == OpenNI.Status.Ok)
                            {
                                if (aS.Equals(colorStream))
                                {
                                    inlineColor++;
                                }
                                else
                                {
                                    inlineDepth++;
                                }

                                aS.ReadFrame().Release();
                            }
                        }
                    }
                }

                Console.ReadLine();
            }

            OpenNI.Shutdown();
            Environment.Exit(0);
        }
Example #13
0
 /// <summary>
 /// Close the OpenNI (Kinect) environment.
 /// </summary>
 public static void Shutdown()
 {
     OpenNI.Shutdown();
 }