#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/imgcodecs/legacy/constants_c.h"
#include "opencv2/imgproc/types_c.h"
using namespace std;
using namespace cv;
int main()
{
cv::Mat img_encode;
img_encode = imread("/home/cqy/Pictures/dog.jpg", CV_LOAD_IMAGE_COLOR);
//jpeg encode image and save to file
std::vector<uchar> data_encode;
vector<int> param= vector<int>(2);
param[0]=CV_IMWRITE_JPEG_QUALITY;
param[1]=95;//default(95) 0-100
imencode(".jpg", img_encode, data_encode, param);
std::string str_encode(data_encode.begin(), data_encode.end());
//png encode image and save to file
//vector<int> param= vector<int>(2);
//param[0]=CV_IMWRITE_PNG_COMPRESSION;
//param[1]=3;//default(3) 0-9.
//imencode(".png",src,buff,param);
//imencode(".png", img_encode, data_encode, param);
//decode image
Mat img_decode;
img_decode = imdecode(data_encode, CV_LOAD_IMAGE_COLOR);
imshow("pic",img_decode);
waitKey(0);
return 0;
}
OpenCV图像编码和解码 imencode和imdecode
最新推荐文章于 2023-02-23 14:50:32 发布