Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resizing Kinect depth image causes error #17

Closed
admayber opened this issue Nov 8, 2018 · 5 comments
Closed

Resizing Kinect depth image causes error #17

admayber opened this issue Nov 8, 2018 · 5 comments

Comments

@admayber
Copy link

admayber commented Nov 8, 2018

The following code block generates a "generic GDI+ error":

using (Pipeline pipeline = Pipeline.Create("PsiNucStorage"))
            {
                KinectSensorConfiguration kinectSensorConfig = new KinectSensorConfiguration();
                kinectSensorConfig.OutputColor = true;
                kinectSensorConfig.OutputDepth = true;
                KinectSensor kinectSensor = new KinectSensor(pipeline, kinectSensorConfig);

                Exporter store = Store.Create(pipeline, "psiKinect", @".\data");

                Emitter<Shared<EncodedImage>> rgbImageStream = kinectSensor.ColorImage.Resize(100, 100).EncodeJpeg(100, DeliveryPolicy.LatestMessage).Out;
                Store.Write(rgbImageStream, "rgbImages", store, true, DeliveryPolicy.LatestMessage);

                Emitter<Shared<EncodedImage>> depthImageStream = kinectSensor.DepthImage.Resize(100, 100).EncodePng(DeliveryPolicy.LatestMessage).Out;
                Store.Write(depthImageStream, "depthImages", store, true, DeliveryPolicy.LatestMessage);

                Console.WriteLine("Starting data collect");
                pipeline.Run();
            }

The culprit seems to be the resize operation on the depth image stream - removing that stage resolves the issue.

@chitsaw
Copy link
Contributor

chitsaw commented Nov 8, 2018

Try the following patch on Sources\Imaging\Microsoft.Psi.Imaging\ImagePool.cs:

diff --git a/Sources/Imaging/Microsoft.Psi.Imaging/ImagePool.cs b/Sources/Imaging/Microsoft.Psi.Imaging/ImagePool.cs
index fcd9f449f..f5a20ed38 100644
--- a/Sources/Imaging/Microsoft.Psi.Imaging/ImagePool.cs
+++ b/Sources/Imaging/Microsoft.Psi.Imaging/ImagePool.cs
@@ -17,10 +17,10 @@ namespace Microsoft.Psi.Imaging
         /// <param name="width">Width of image requested</param>
         /// <param name="height">Height of image requested</param>
         /// <param name="pixelFormat">Pixel format for requested image</param>
-        /// <returns>Returns an image frmo the pool</returns>
+        /// <returns>Returns an image from the pool</returns>
         public static Shared<Image> GetOrCreate(int width, int height, PixelFormat pixelFormat)
         {
-            return KeyedSharedPool<Image, ValueTuple<long, PixelFormat>>.GetOrCreate(ValueTuple.Create((long)(width * height), pixelFormat), () => Image.Create(width, height, pixelFormat));
+            return KeyedSharedPool<Image, ValueTuple<int, int, PixelFormat>>.GetOrCreate(ValueTuple.Create(width, height, pixelFormat), () => Image.Create(width, height, pixelFormat));
         }
 
         /// <summary>

@admayber
Copy link
Author

admayber commented Nov 8, 2018

Error still occurs, unfortunately. In case it's helpful, the error is originating at line 216 of Microsoft.Psi.Imaging\Operators.cs, in the middle of this code block:

graphics.ScaleTransform(xScale, yScale);
graphics.DrawImage(image.ToManagedImage(), new Point(0, 0));   \\ line that causes error
return ImagePool.GetOrCreate(bitmap);

@chitsaw
Copy link
Contributor

chitsaw commented Nov 8, 2018

Thanks for the additional info. We'll investigate further and get back to you.

@chitsaw
Copy link
Contributor

chitsaw commented Nov 8, 2018

The Resize operator does not work with the raw depth image format. In order to perform imaging operations on the depth stream, it should first be converted to a color or grayscale image like so:

var depthImageStream = kinectSensor.DepthImage.ToGray().Resize(100, 100).EncodeJpeg(90, DeliveryPolicy.LatestMessage).Out;

We should probably throw a more helpful exception than the underlying generic GDI+ error.

@admayber
Copy link
Author

admayber commented Nov 8, 2018

Ahh okay, that corrects the issue for me. Thank you!

@admayber admayber closed this as completed Nov 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants