当前位置:   article > 正文

C++中opencv在内存中将bmp转jpg_opencv bmp图片转jpg图片 c++

opencv bmp图片转jpg图片 c++
#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); 或者
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
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))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/523033
推荐阅读
相关标签
  

闽ICP备14008679号