Compress Mat in Jpeg And save the result in memory

I know that the cv :: imwrite function can compress cv::Mat in Jpeg and save it to a file. But now I want to keep it in memory, like an uchar array. That way I can send the array to another and it can write data to the jpeg file. Is there anyone who can help me?

+6
source share
1 answer

Since you did not specify a programming language. I will give you an 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); 
+6
source

All Articles