Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a byte array that represents a .jpg file that I want to convert directly to an OpenCV Mat object.

I have something like

byte* data; // Represents a JPG that I don't want to disk and then read.
// What goes here to end up with the following line?
cv::Mat* image_representing_the_data;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.5k views
Welcome To Ask or Share your Answers For Others

1 Answer

the previously mentioned method will work fine, if it's PIXEL data.

if instead, you have a whole jpg FILE in memory, headers, compression, and all, it won't work.

in that case you want:

Mat img = imdecode(data);

which will do the same as imread(), only from memory, not from a filename


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...