赞
踩
#include "opencv2/opencv.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/core.hpp>
int main()
{
std::vector<unsigned char> buff;
cv::Mat pSrcData = *(cv::Mat*)image;//自己的图像
std::vector<int> param = std::vector<int>(2);
param[0] = CV_IMWRITE_JPEG_QUALITY;
param[1] = 50; // default(95) 0-100
cv::imencode(".jpg", pSrcData, buff, param);
cv::Mat jpg_mat = cv::imdecode(cv::Mat(buff),1);
// cv::imwrite("D:\\1.jpg",pSrcData, param); 或者
}
import cv2
import numpy as np
path = r"D:\model\0_2_0_LJ12532060332.bmp"
bmp = cv2.imread(path)
bmp = bmp
cv2.imwrite(r"D:\model\opencv4_test3.jpg", bmp, [cv2.IMWRITE_JPEG_QUALITY,75])
_, img_encode = cv2.imencode(".jpg", bmp,[cv2.IMWRITE_JPEG_QUALITY,75])
imgString = img_encode.tostring()
nparr = np.fromstring(imgString,np.uint8)
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
jpg = cv2.imread(r"D:\model\0_2_0_LJ12532060332__3.jpg")
jpg = jpg
cv2.imwrite(r"D:\model\opencv4_test4.jpg", jpg)
jpg0 = cv2.imread(r"D:\model\opencv_test2.jpg")
jpg1 = cv2.imread(r"D:\model\opencv4_test5.jpg")
# jpg1 = jpg0
# cv2.imwrite(r"D:\model\opencv4_test5.jpg", jpg1)
print(np.max(jpg-jpg0),np.min(jpg-jpg0))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。