Opencv读取图片像素值

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;


int main()
{
  Mat img1;
  img1 = imread("D://images//111.jpg");
  if (img1.empty())
  {
    cout << "could not load image..."<< endl;
    return 0;
  }

  imshow("win1",img1);

  for (int row =0;row< img1.rows;row++)
  {
    for (int col=0;col<img1.cols;col++)
    {
      Vec3b vec_3 = img1.at<Vec3b>(row, col);
      int b = vec_3[0];
      int g = vec_3[1];
      int r = vec_3[2];
      cout << "B:"<<b<< " G:" << g << " R:" <<r<< endl;
    }
  }

  waitKey(0);
  return 0;
}

 

posted @ 2018-10-24 18:51  西北逍遥  阅读(4547)  评论(0编辑  收藏  举报