Opencv3保存16位深度图

#include 
#include 

void main()
{
	int mark = 1;
	if (mark == 0)
	{
		cv::Mat src = (cv::Mat_(2, 2) << 1111, 22222, 33333, 4444);
		cv::Mat dst;
		src.convertTo(dst, CV_16UC1);
		std::vector compression_params;
		compression_params.push_back(cv::IMWRITE_PNG_COMPRESSION);
		compression_params.push_back(0);
		compression_params.push_back(cv::IMWRITE_PNG_STRATEGY);
		compression_params.push_back(cv::IMWRITE_PNG_STRATEGY_DEFAULT);

		cv::imwrite("../public/1111.png", dst, compression_params);

		cv::Mat mat = cv::imread("../public/1111.png", cv::IMREAD_UNCHANGED);
	}
	else if (mark == 1)
	{
		cv::Mat src = (cv::Mat_(2, 2) << 3, 4, 5, 7);
		cv::Mat dst;
		src.convertTo(dst, CV_16UC1);
		std::vector compression_params;
		compression_params.push_back(cv::IMWRITE_PNG_COMPRESSION);
		compression_params.push_back(0);
		compression_params.push_back(cv::IMWRITE_PNG_STRATEGY);
		compression_params.push_back(cv::IMWRITE_PNG_STRATEGY_DEFAULT);

		cv::imwrite("../public/1111.png", dst, compression_params);

		cv::Mat mat = cv::imread("../public/1111.png", cv::IMREAD_UNCHANGED);
	}
	
}

 

你可能感兴趣的:(Opencv3学习笔记)