I am currently working on a project involving 3D object recognition from RGB-D data obtained from the Structure sensor. For this, I need to create a database of such images, and consequently be able to save pairs of RGB and depth images streamed from the sensor.
The Viewer sample app creates an UIImage from both color and colored depth data in order to display them, as follows:
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGBitmapInfo bitmapInfo; bitmapInfo = (CGBitmapInfo)kCGImageAlphaNoneSkipLast; bitmapInfo |= kCGBitmapByteOrder32Big; NSData *data = [NSData dataWithBytes:_coloredDepthBuffer length:cols * rows * 4]; CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)data); //toll-free ARC bridging CGImageRef imageRef = CGImageCreate(cols, //width rows, //height 8, //bits per component 8 * 4, //bits per pixel cols * 4, //bytes per row colorSpace, //Quartz color space bitmapInfo, //Bitmap info (alpha channel?, order, etc) provider, //Source of data for bitmap NULL, //decode false, //pixel interpolation kCGRenderingIntentDefault); //rendering intent // Assign CGImage to UIImage _currentColoredDepthImage = [UIImage imageWithCGImage:imageRef]; _depthImageView.image = _currentColoredDepthImage;
Here the UIImage is associated with an image view to display it, but we can also save the image to the iPad since it is a UIImage object (by converting it to PNG data for instance). This works for color images, but in my case I also want to save also depth image in the format of floating-point png. I wanted to know if there was a more direct means to save pairs of depth and RGB images to the disk, or if it is not the case which parameters I should use for the creation of a floating-point depth image to be saved later.