Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compress Mat into Jpeg And save the result into memory

Tags:

c++

opencv

jpeg

mat

I know that the function cv::imwrite can compress a cv::Mat into Jpeg and save it to a file. But now I want to save it into memory, like a array of uchar. So, I can send the array to another one ,and it can write the data into a jpeg file. Is there any one can help me out?

like image 284
cirfe Avatar asked Nov 05 '15 01:11

cirfe


1 Answers

Since You did not specify a programming language. I am going to give you the answer in C++.

    std::vector<uchar> buff;//buffer for coding
    std::vector<int> param(2);
    param[0] = cv::IMWRITE_JPEG_QUALITY;
    param[1] = 80;//default(95) 0-100
    cv::imencode(".jpg", mat, buff, param);
like image 144
Humam Helfawi Avatar answered Oct 02 '22 17:10

Humam Helfawi