Using Unprocessed raw data for OpenCV

Hi everyone,

First of all thanks for that wonderful library !

I've some issues, passing Raw Datas to an OpenCV Mat.

At first i used dcraw, but there is too much processing for me, my output images is blurred and pinked (yeah my picture has too much red in it i don't know why). So i tried to change dcraw processing params, but it was worse.

So i'm trying to used the unprocessed data and to fill a cv::Mat with it ! I read a lot of topics in this forum, and tried a lot of fixes, but i couldn't manage to do what i needed.

Image::Image(const char* file)
{
	LibRaw rawProcessor;
	libraw_processed_image_t *tmpImg;
 
	if(rawProcessor.open_file(file) != LIBRAW_SUCCESS)
	{
		// !!! Exception to handle !!!
	}
	else
	{
		rawProcessor.unpack();
		//rawProcessor.raw2image();
 
		//rawProcessor.imgdata.params.no_interpolation = 1;
		//rawProcessor.imgdata.params.no_auto_scale = 1;
		//rawProcessor.imgdata.params.no_auto_bright = 1;
 
		//int check = rawProcessor.dcraw_process();
		//tmpImg = rawProcessor.dcraw_make_mem_image(&check);
 
		// Init image
		Img = cv::Mat(rawProcessor.imgdata.sizes.width, rawProcessor.imgdata.sizes.height, CV_16UC3, rawProcessor.imgdata.rawdata.raw_image);
 
		// Init datas
		cameraModel = (std::string) rawProcessor.imgdata.idata.make + "-" + rawProcessor.imgdata.idata.model;
		shutterTime = rawProcessor.imgdata.other.shutter;
	}
 
	// Free rawProcessor
	rawProcessor.recycle();
}

And I can't do a single thing on this matrix. It seems that rawProcessor.imgdata.rawdata.raw_image is empty or Null ...

If anyone can help me, i just come back to cpp after a long break using matlab i may make some basic cpp mistakes and i'm really sorry about that.

Greetings

bdaniel

Forums: 

Do you use bayer-matrix

Do you use bayer-matrix camera to test with?

If not, rawdata.raw_image will be NULL, while rawdata.color3_image or rawdata.color4_image is not

-- Alex Tutubalin

Thanks,

Thanks,

I had finally some rawdatas but, it wasn't what i expected. It seems that i have a monochromous picture only raw_image is filled how can i acces the raw data without processes ?

Because i've always worked with ppm and pgm pictures, for that projecti needd to use my .NEF in order to make some deep image processing on it with OpenCV. I'd like to get frow libraw a Matrix (Height x Width x Channels (here 3)) to put it in OpenCV and start to process the images.

Really thanks again !

Bdaniel

Bayer images contains only

Bayer images contains only one color channel information per pixel (each pixel is red or green or blue).
To get full-colored image from raw bayer data one need to
1) decode bayer (one component per pixe) data
2) do demosaic (de-bayer) so:
- apply white balance
- interpolate color data for missing color values
- convert to output color space
- do gamma correction.

In LibRaw this is made by this call sequence:
open_file() ; // read image metadata
unpack(); // decode bayer data
dcraw_process(); // white balance, color interpolation, color space conversion
dcraw_make_mem_image(); // gamma correction, image rotation, 3-component RGB bitmap creation

-- Alex Tutubalin