记录-输出Mat depth或ir像素值

输出depth和Ir

通过ptr<>()指针方式访问Mat中的像素值

// 定义两mat存储crop之后的depth和ir
	cv::Mat depth_img_crop = depth_img;
	cv::Mat ir_img_crop = ir_img;
	// 打印depth像素值
	int depth_rowNumber = depth_img.rows;  // 行数
	int depth_colNumber = depth_img.cols * depth_img.channels();   // 列数*channel数=每行的元素个数
	int depth_max = 0, depth_min = 65535;
	for (int i = 0; i < depth_rowNumber; ++i) {
		ushort* data = depth_img.ptr<ushort>(i);  // 获取第i行的首地址
		for (int j = 0; j < depth_img.cols; ++j) {
			int intensity = data[j];
			if (depth_max < intensity) {
				depth_max = intensity;
			}
			if (depth_min > intensity) {
				depth_min = intensity;
			}
			std::cout << intensity << " ";
		}
		std::cout << std::endl;
	}
	std::cout << "depth_max: " << depth_max << " depth_min: " << depth_min << std::endl;
	system("pause");

	// 打印ir像素值
	int ir_rowNumber = ir_img.rows;  // 行数
	int ir_colNumber = ir_img.cols * ir_img.channels();   // 列数*channel数=每行的元素个数
	int ir_max = 0, ir_min = 255;
	for (int i = 0; i < ir_rowNumber; ++i) {
		uchar* data = ir_img.ptr<uchar>(i);  // 获取第i行的首地址
		for (int j = 0; j < ir_img.cols; ++j) {
			int intensity = data[j];
			if (ir_max < intensity) {
				ir_max = intensity;
			}
			if (ir_min > intensity) {
				ir_min = intensity;
			}
			std::cout << intensity << " ";
		}
		std::cout << std::endl;
	}
	std::cout << "ir_max: " << ir_max << " ir_min: " << ir_min << std::endl;
	system("pause");

你可能感兴趣的:(1024程序员节,c++,opencv,图像处理)