Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Following code snippet would help to load raw image to OpenCV Mat structure and then you can do further processing like demosaicing or some detection algorithms.

Mat img;
FILE *fp = NULL;
char *imagedata = NULL;
int framesize = IMAGE_WIDTH * IMAGE_HEIGHT;

//Open raw Bayer image.
fp = fopen("filename.raw", "rb");

//Memory allocation for bayer image data buffer.
imagedata = (char*) malloc (sizeof(char) * framesize);

//Read image data and store in buffer.
fread(imagedata, sizeof(char), framesize, fp);

//Image dimension.
imageSize.height = IMAGE_WIDTH;
imageSize.width = IMAGE_HEIGHT;

//Create Opencv mat structure for image dimension. For 8 bit bayer, type should be CV_8UC1.

memcpy(, imagedata, framesize);



//Perform demosaicing process
cvtColor(img, RGBImage, CV_BayerBG2BGR);

Once color space is converted to BGR, further processing like edge detection or enhancement can be done. Hope this helps.