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

论坛 期权论坛 脚本     
匿名技术用户   2021-1-6 18:09   61   0

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

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

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

附上我的小程序:

#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!

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP