Azure-Kinect-Sensor-SDK icon indicating copy to clipboard operation
Azure-Kinect-Sensor-SDK copied to clipboard

it looks like distorted Depth Image of Object

Open yeongwoonIm opened this issue 6 years ago • 10 comments

Depth Image of Object looks like distorted.

Mode : NFOV unbinned

Depth Original Image Depth Image is just expressing Depth as RGB(255,255,255). depth IR Original Image IR Image is threshold of 350. IR

The other TOF Camera doesn't look like distorted.. Intel TOF, etcs.. It comes to undistorted Data(IR, Depth, RGB).

Could you fix that When I call this function. it already has been undistorted it. and I use it.

Capture capture = device.GetCapture();

I searched issues. but there is no solutions that I want it.

Thank you.

yeongwoonIm avatar Oct 12 '20 03:10 yeongwoonIm

Capture cap=k4a::capture::create(); device.get_capture(cap); k4a::image color=cap.get_color_image(); k4a::image depth=cap.get_depth_image() k4a::image ir=cap.get_ir_image()

VegetableWithChicken avatar Oct 12 '20 04:10 VegetableWithChicken

Could you please share the original image prior to un-distortion.

qm13 avatar Oct 12 '20 17:10 qm13

Could you please share the original image prior to un-distortion.

Those Images are Original Image. it just coded. This is viewer Image viewer

I tested lens undistortion. I got lens parameters from this code.

Calibration calibration = device.GetCalibration(); var cal = calibration.DepthCameraCalibration; Console.WriteLine(string.Format("width:{0}", cal.ResolutionWidth)); Console.WriteLine(string.Format("height:{0}", cal.ResolutionHeight)); Console.WriteLine(string.Format("paramcount:{0}", cal.Intrinsics.ParameterCount)); for (int i = 0; i < cal.Intrinsics.ParameterCount; i++) { Console.WriteLine(string.Format("param[{0}]:{1}", i, cal.Intrinsics.Parameters[i])); }

and I apply parameters. then I got this. distortion

it looks like original image that is not undistorted.

it means the Depth data already had been undistorted when I got it.

Am i right??

so could you fix that ??

yeongwoonIm avatar Oct 13 '20 01:10 yeongwoonIm

Capture cap=k4a::capture::create(); device.get_capture(cap); k4a::image color=cap.get_color_image(); k4a::image depth=cap.get_depth_image() k4a::image ir=cap.get_ir_image()

it;'s C++ Code. I code C#. and it may be same.

Capture capture = device.GetCapture(); short[] realtime_depth = capture.Depth.GetPixels().ToArray(); short[] realtime_activeIR = capture.IR.GetPixels().ToArray();

yeongwoonIm avatar Oct 13 '20 01:10 yeongwoonIm

#1238 had the same issue. It was believed that it's an hardware error, but it's not.

DirkKramer avatar Oct 13 '20 06:10 DirkKramer

#1238 had the same issue. It was believed that it's an hardware error, but it's not.

#1238 is closed... is it solve?? or still processing??

yeongwoonIm avatar Oct 13 '20 08:10 yeongwoonIm

The depthimage is still distorted, but in our usecase I found a workaround.

In our case we want to detect objects in the color images and use that detection to filter the pointcloud.

First we crop out the depthimage out of the color image. so for example if you use NFOV Unbinned with 720p color resolution. -Color =1280x720 -Depth=640x576

You crop your color image to: X=1280/2-640/2 Y=720/2-576/2 Width=640 Heigth=576

Second step is getting the boundingboxes

Third step is use that boundingbox to filter the pointcloud. To do this you have to apply the 6 degree rotation to your boundingboxes (see documentation).

I dont know if this is helpfull because the distortion is not really gone. Knipsel

DirkKramer avatar Oct 13 '20 08:10 DirkKramer

The wide field of view of the AKDK depth sensor meant it was more optimal to use an f-theta (fisheye) rather than a rectilinear lens (e.g. a typical photographic camera or most machine vision cameras). This results in barrel distortion that results in some flat objects appearing curved, similar to a color image taken through a fish-eye lens. Most competitive products do not have such a wide field of view and do not need to make this trade-off.

Many image processing and machine learning algorithms make the assumption of a rectilinear lens or an explicitly undistorted image. The RGB sensor on the Kinect for Azure has rectilinear distortion, however the raw depth data provided through the API is not automatically resampled to remove the barrel distortion. The Sensor SDK supports mapping/resampling the depth data from the raw images to the RGB images if that is useful (using k4a_transformation_create and k4a_transformation_depth_image_to_color_camera functions), which will remove the distortion but may crop/not provide the exact resolution that you need.

An alternative approach is to use the calibrated camera intrinsic (get using k4a_device_get_calibration) with OpenCV or alternative CV library to undistort the image.

qm13 avatar Oct 13 '20 23:10 qm13

The depthimage is still distorted, but in our usecase I found a workaround.

In our case we want to detect objects in the color images and use that detection to filter the pointcloud.

First we crop out the depthimage out of the color image. so for example if you use NFOV Unbinned with 720p color resolution. -Color =1280x720 -Depth=640x576

You crop your color image to: X=1280/2-640/2 Y=720/2-576/2 Width=640 Heigth=576

Second step is getting the boundingboxes

Third step is use that boundingbox to filter the pointcloud. To do this you have to apply the 6 degree rotation to your boundingboxes (see documentation).

I dont know if this is helpfull because the distortion is not really gone. Knipsel

Wow~ You have done great job !! it's really helpfull

yeongwoonIm avatar Oct 14 '20 02:10 yeongwoonIm

The wide field of view of the AKDK depth sensor meant it was more optimal to use an f-theta (fisheye) rather than a rectilinear lens (e.g. a typical photographic camera or most machine vision cameras). This results in barrel distortion that results in some flat objects appearing curved, similar to a color image taken through a fish-eye lens. Most competitive products do not have such a wide field of view and do not need to make this trade-off.

Many image processing and machine learning algorithms make the assumption of a rectilinear lens or an explicitly undistorted image. The RGB sensor on the Kinect for Azure has rectilinear distortion, however the raw depth data provided through the API is not automatically resampled to remove the barrel distortion. The Sensor SDK supports mapping/resampling the depth data from the raw images to the RGB images if that is useful (using k4a_transformation_create and k4a_transformation_depth_image_to_color_camera functions), which will remove the distortion but may crop/not provide the exact resolution that you need.

An alternative approach is to use the calibrated camera intrinsic (get using k4a_device_get_calibration) with OpenCV or alternative CV library to undistort the image.

Thank you for good advice. the distortion almost removed. undistortion

and I want to ask one more things.

How can I get IR data? I can't see code of getting IR data in C# API.

this function return only Depth Datas...

DepthImageToColorCamera (Capture capture)

//C# Code //width & height will change [640x576] to [1280x720]

Device device = Device.Open(0); DeviceConfiguration deviceConfiguration = new DeviceConfiguration(); deviceConfiguration.ColorFormat = Microsoft.Azure.Kinect.Sensor.ImageFormat.ColorBGRA32; deviceConfiguration.DepthMode = DepthMode.NFOV_Unbinned; deviceConfiguration.CameraFPS = FPS.FPS30; deviceConfiguration.SynchronizedImagesOnly = true; deviceConfiguration.ColorResolution = ColorResolution.R720p; device.StartCameras(deviceConfiguration); Calibration calibration = device.GetCalibration(); Transformation transformation = calibration.CreateTransformation(); Capture capture = device.GetCapture(); Microsoft.Azure.Kinect.Sensor.Image image = transformation.DepthImageToColorCamera(capture); // use this array to do your work short[] realtime_depth = image.GetPixels().ToArray();

I found the way how to get IR Data(undistortion) but it has problem. it has a lot of processing time... this is the code..

Device device = Device.Open(0); DeviceConfiguration deviceConfiguration = new DeviceConfiguration(); deviceConfiguration.ColorFormat = Microsoft.Azure.Kinect.Sensor.ImageFormat.ColorBGRA32; deviceConfiguration.DepthMode = DepthMode.NFOV_Unbinned; deviceConfiguration.CameraFPS = FPS.FPS30; deviceConfiguration.SynchronizedImagesOnly = true; deviceConfiguration.ColorResolution = ColorResolution.R720p; device.StartCameras(deviceConfiguration); Calibration calibration = device.GetCalibration(); Transformation transformation = calibration.CreateTransformation(); Capture capture = device.GetCapture(); Microsoft.Azure.Kinect.Sensor.Image depthImage = new Microsoft.Azure.Kinect.Sensor.Image(ImageFormat.Depth16, width, height); Microsoft.Azure.Kinect.Sensor.Image irImage = new Microsoft.Azure.Kinect.Sensor.Image(ImageFormat.Custom16, width, height); Microsoft.Azure.Kinect.Sensor.Image OirImage = new Microsoft.Azure.Kinect.Sensor.Image(ImageFormat.Custom16, 640, 576); for(int x = 0;x < 640 ; x ++) { for(int y = 0 ; y < 576 ; y++) { OirImage.SetPixel(y, x, capture.IR.GetPixel(y,x)); } } transformation.DepthImageToColorCameraCustom(capture.Depth, OirImage, depthImage, irImage, TransformationInterpolationType.Linear, 0); // use this array to do your work short[] realtime_depth = depthImage.GetPixels().ToArray(); short[] realtime_activeIR = irImage.GetPixels().ToArray();

Result Image.. un1 un2

yeongwoonIm avatar Oct 14 '20 02:10 yeongwoonIm