file loaded from std::ifstream to opencv image

asked 2015-03-30 22:37:29 -0500

deshan gravatar image

updated 2015-10-08 09:06:56 -0500

Hi all,

I have a image file as a byte buffer loaded using a Input stream as below.

std::ifstream is("image.jpg", std::ifstream::binary);
char * buffer; // image.jpg store in this buffer

Now has some difficulties for me to convert this one into a opencv image. Unfortunately I cannot use cvLoadImage function. I tried below but failed.

 cv::Mat mat= cv::Mat(imageHeight, imageWidth, CV_8UC3, buffer);

Getting an error when I want to display it.

cv::imshow("Img", mat);

Please help. Thanks

edit retag flag offensive close merge delete

Comments

2

you will have to decode that buffer first , to get a cv::Mat.

berak gravatar imageberak ( 2015-03-31 01:58:30 -0500 )edit