博主真的很懒欸,要不是哥哥的监督我就又要废了。come on,进入正题

先看效果图,是不是大家想找的那种呢?

两张图片是一样的哦,只是读出了RGB值.原因是我并没有在代码里对图片进行任何设置

 

opencv——Mat利用指针得到图像的RGB值(1)

 

附上我的小程序:

#include <iostream>

#include "opencv.hpp"

#include "opencv2/core/core.hpp"

#include "opencv2/highgui/highgui.hpp"

using namespace std;

void salt(cv::Mat image, int n)
//读出RGB像素值
{
	for (size_t nrow = 0; nrow < image.rows; nrow++)
	{
		uchar* data = image.ptr<uchar>(nrow);
		for (size_t ncol = 0; ncol < image.cols * image.channels(); ncol++)
		{
			
			cout << "I am RGB"<<int(data[ncol])<< endl;
		}
		cout << endl;
	}


}

int main()

{

	cv::Mat image = cv::imread("E:\\tutu\\tiger.jpg");
	//读入我的小老虎图片,绝对路径

	cv::imshow("raw_picture", image);
	//显示窗口名字,第一次显示原图

	salt(image, 30000);
	
	//传入参数
	//cv::namedWindow("Image_salted");
	
	cv::imshow("Image_salted", image);
	//显示窗口名字,第二次显示出函数处理过后的图片,注意效果没变哦
	cv::waitKey(0);

}

 

end!

 

 

 

 

 

相关文章:

  • 2022-12-23
  • 2021-09-28
  • 2021-07-04
  • 2022-12-23
  • 2021-05-05
  • 2021-11-18
  • 2021-04-12
  • 2021-10-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-12
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案