Ask Your Question
0

Unable to open raw image through opencv

asked 2015-03-23 06:03:30 -0500

aries gravatar image

updated 2015-03-24 01:21:18 -0500

Spark gravatar image

I am trying to open a raw color image that I have captured from the camera using opencv. But imread does not seem to be able to open it. Below is my code:

Mat original = Mat(1792,1344, CV_8UC3);
original = imread("image.raw", 1);
if(original.empty()){
cout<<"unable to read image";
waitkey(10);
exit(0);    
}

Can someone please help me find the solution?

PS: I am using my own debayering technique to get the raw image from the sensor and writing it to the disk.

edit retag flag offensive close merge delete

Comments

And in which format do you write it to the disk?

FooBar gravatar imageFooBar ( 2015-03-23 06:35:53 -0500 )edit
1

imread() can't read raw images. you'll have to build your own loading routine for that.

berak gravatar imageberak ( 2015-03-23 06:57:22 -0500 )edit

Hello,

is there a way to use the imagedata pointer direct in the Mat class. on slow System, memcpy Need much time.

sample img.create(Height, Width, Format, imagedata)

so no internal malloc, no memcpy, no free is needed.

Johann

Johann gravatar imageJohann ( 2016-01-19 09:50:23 -0500 )edit

@Johann, some things:

  • do not post answers, if you got a question
  • dare to ask your own question
berak gravatar imageberak ( 2016-01-19 09:56:57 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-03-24 01:20:59 -0500

Spark gravatar image

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.
img.create(IMAGE_HEIGHT, IMAGE_WIDTH, CV_8UC1);

memcpy(img.data, imagedata, framesize);

free(imagedata);

fclose(fp);

//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.

edit flag offensive delete link more

Comments

imageSize.height = IMAGE_WIDTH; Is this some kind of joke? Why have Height and Width been interchanged? Is imageSize of class Size? It hasn't been declared.

zscore gravatar imagezscore ( 2018-02-26 00:32:22 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-03-23 06:03:30 -0500

Seen: 13,198 times

Last updated: Mar 24 '15