Beispiel #1
0
 private void FrmMainLoad(object sender, EventArgs e)
 {
     this.HandleError(OpenNI.Initialize());
     OpenNI.OnDeviceConnected    += this.OpenNiOnDeviceConnectionStateChanged;
     OpenNI.OnDeviceDisconnected += this.OpenNiOnDeviceConnectionStateChanged;
     this.UpdateDevicesList();
 }
Beispiel #2
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();
 }
        private void OpenNI2_Initialize()
        {
            OpenNI.Status status = OpenNI.Initialize();
            if (status != OpenNI.Status.Ok)
            {
                string errMsg = string.Format(@"Failed to initialize OpenNI2: {0} - {1}", status, OpenNI.LastError);
                MessageBox.Show(errMsg, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            this.Dispatcher.Invoke((Action)(() =>
            {
                this.txtDevice.Text = "OpenNI2 Module is ready.\n";
            }));
        }
Beispiel #4
0
        public void initAndStart(string deviceName)
        {
            // Initialize OpenNI
            OpenNI.Initialize();

            DeviceInfo device = updateDeviceList(deviceName);
            // init sensor
            bool initSuccessful = initSensor(device);

            if (initSuccessful)
            {
                // start sensor
                startSensor();
            }
        }
Beispiel #5
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();
        }
Beispiel #6
0
    // Start is called before the first frame update
    void Start()
    {
        OpenNI.Initialize();

        OpenNI.OnDeviceConnected    += OnDeviceConnectionStateChanged;
        OpenNI.OnDeviceDisconnected += OnDeviceConnectionStateChanged;
        var devices = OpenNI.EnumerateDevices();

        Debug.Log($"Found {devices.Length} devices");

        // foreach (var d in devices) {
        //     Debug.Log(d.Name);
        // }

        // connect to first one
        if (devices.Length > 0)
        {
            OnDeviceConnectionStateChanged(devices[0]);
        }
    }
 private void Init()
 {
     try
     {
         HandleError(OpenNI.Initialize());
         NiTE.Initialize();
         OpenNI.OnDeviceConnected    += OpenNiOnDeviceConnectionStateChanged;
         OpenNI.OnDeviceDisconnected += OpenNiOnDeviceConnectionStateChanged;
         OpenNI.OnDeviceStateChanged += OpenNiOnDeviceStateChanged;
         UpdateDevicesList();
         notify.Visible = !Settings.Default.AutoNotification;
         ReadSettings();
     }
     catch (Exception ex)
     {
         MessageBox.Show(
             string.Format("Fatal Error: {0}", ex.Message),
             @"Execution Error",
             MessageBoxButtons.OK,
             MessageBoxIcon.Error);
         Environment.Exit(1);
     }
 }
Beispiel #8
0
        public KinectOpenNi2()
        {
            HandleError(OpenNI.Initialize());

            DeviceInfo[] devices = OpenNI.EnumerateDevices();
            if (devices.Length == 0)
            {
                HandleError(OpenNI.Status.NO_DEVICE);
            }

            kinectDevice = devices[0].OpenDevice();

            colorSensor = kinectDevice.CreateVideoStream(Device.SensorType.COLOR);
            VideoMode[] videoModes = colorSensor.SensorInfo.getSupportedVideoModes();
            colorSensor.VideoMode = videoModes[1];
            colorSensor.Start();
            colorSensor.onNewFrame += new VideoStream.VideoStreamNewFrame(colorSensor_onNewFrame);

            depthSensor           = kinectDevice.CreateVideoStream(Device.SensorType.DEPTH);
            videoModes            = depthSensor.SensorInfo.getSupportedVideoModes();
            depthSensor.VideoMode = videoModes[0];
            depthSensor.Start();
            depthSensor.onNewFrame += new VideoStream.VideoStreamNewFrame(depthSensor_onNewFrame);
        }
Beispiel #9
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();
        }
Beispiel #10
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);
        }
Beispiel #11
0
 /// <summary>
 /// Open the OpenNI (Kinect) environment.
 /// </summary>
 /// <returns>True if the process was successful; false otherwise.</returns>
 public static bool Initialize()
 {
     return(OpenNI.Initialize() == OpenNI.Status.Ok);
 }