falahati / NiWrapper.Net

OpenNI 2 and NiTE 2 .Net Wrapper
http://www.falahati.net
GNU Lesser General Public License v2.1
52 stars 30 forks source link

Problem with DEPTH_TO_COLOR ImageRegistration in Kinect xbox #7

Closed bharatrocks100 closed 10 years ago

bharatrocks100 commented 10 years ago

Hi, I am wondering, why am I not able to change image registration mode for Kinect xbox as follows:

"if(device.isImageRegistrationModeSupported(Device.ImageRegistrationMode.DEPTH_TO_COLOR)) device.ImageRegistration = Device.ImageRegistrationMode.DEPTH_TO_COLOR;"

Above code with xbox Kinect just skips registration part, as if it does not support DEPTH_TO_COLOR mapping. However, it runs well both depth and Image stream simultaneously on NiViewer Sample application. How ???

Any help appreciated ! Thank you :)

falahati commented 10 years ago

As far as I know you must have both depth and color video streams in your code. (Unlike other devices) Then you must make sure that they are using same resolution (I believe this is your problem, you changed one but not other). Then you can request for Image registration.

Shortest code you can write to test this functionality is as follow:

 Device device = Device.Open(Device.ANY_DEVICE);
 VideoStream depthStream = device.CreateVideoStream(device.SensorType.DEPTH);
 VideoStream colorStream = device.CreateVideoStream(device.SensorType.COLOR);
 device.ImageRegistration = device.ImageRegistrationMode.DEPTH_TO_COLOR;
 depthStream.Start();
 colorStream.Start();
bharatrocks100 commented 10 years ago

But, anyway problem still persists.

It said: Device setProperty(5) failed

Please note that I'm using kinect xbox sensor, not prime sense! as said before, NiViewer sample application runs both streams at a time.

error_snapshot

npapadop commented 10 years ago

Hi, I had the same problem (i'm using kinect xbox sensor). For some reason i had to start the streams and then set the DepthToColor registration mode, to avoid such error. I dont know if this is the correct way though.

Edit: However following the example of Openi Cookbook for Color to depth overlay seems to work fine.

bharatrocks100 commented 10 years ago

@npapadop , As you said, I turned on both streams before DepthToColor registration. But, it does NOT help me. Also, please elaborate which example of openni cookbook are you talking about ??

bharatrocks100 commented 10 years ago

Detailed error info attached here: As you can see, its a "System.NonImplementedException" occurred with kinect xbox sensor on this line:

this.device.ImageRegistration = Device.ImageRegistrationMode.DEPTH_TO_COLOR;

error_detail

falahati commented 10 years ago

Can you run "CustomBitmapCopyVB" sample?

I tested with Kinect for Xbox and it was fine. Using Kinect SDK 1.7.

npapadop commented 10 years ago

I'm referring to example of Openni Cookbook (falahati's book) in page 193, Chapter: Overlaying the depth frame over the image frame. I attached you the sequence of my code. Working also with SDK 1.7 as falahati mentioned above.

codesample

bharatrocks100 commented 10 years ago

Sorry guys, I was away from code for last couple of days. Today, I returned to same project and tried above code that @npapadop had suggested previously. However, despite different efforts, same could not work for me !! As you can see here in screenshot, that error is still same as previous...

@falahati Please, reopen this issue thread. I could not checked "CustomBitmapCopyVB" on my VS 2010 . But, Can you please refer some c# project if you have in place to check working on kinect xbox !

error_detail3

error_detail2

falahati commented 10 years ago

Following code worked perfect for me:

namespace ConsoleImageRegistration
{
    using System;
    using System.Drawing;
    using OpenNIWrapper;

    class Program
    {
        private static Device device;

        private static VideoStream depthStream, colorStream;
        static void Main(string[] args)
        {
            try
            {
                OpenNI.Initialize();
                device = Device.Open(Device.ANY_DEVICE);

                depthStream = device.CreateVideoStream(Device.SensorType.DEPTH);
                depthStream.VideoMode = new VideoMode
                {
                    DataPixelFormat = VideoMode.PixelFormat.DEPTH_1MM,
                    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.DEPTH_TO_COLOR;
                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();
        }
    }
}

Based on same code I created a sample named "ConsoleImageRegistration" that you can find in "Samples" directory.

If you still failed to run the above code, there is probably a problem with Kinect SDK, device or OpenNI itself.

bharatrocks100 commented 10 years ago

Hi Falahati, Firstly, thank you for reopening this thread again..! Perhaps, I have to check kinect xbox and your console sample code on another machine, as your sample code ConsoleImageRegistration on my machine, still returns same error as below: (Yeah...I am using Kinect xbox 360)

error_detail4

falahati commented 10 years ago

You use latest version of NiWrapper and Kinect SDK right? Because there wasn't support for Kinect Color over Depth registration prior to the OpenNI 2.1.x (NiWrapper 2.1.x)

bharatrocks100 commented 10 years ago

I am using Kinect SDK v1.7 and OpenNI 2.2 sdk + NiTE 2.2.0.5... Further, Can you please provide me URL to latest (kinect xbox compatible) release of NiWrapper.NET, NiWrapper files that worked for your kinect xbox ??

falahati commented 10 years ago
bharatrocks100 commented 10 years ago

On a positive note, I guess, that problem has been resolved with files you have provided to me in the URL previously and Kinect SDK v1.8 :-) Now, image registration works perfectly on kienct xbox.

Thanks a ton, for your immense help !