zoukankan      html  css  js  c++  java
  • Opencv3——遍历Mat像素值

    #include <opencv2/opencv.hpp>

    #include <iostream>

    using namespace cv;

    using namespace std;

    int main(int artc, char** argv) {

             Mat src = imread("D:/test.png");

             if (src.empty()) {

                      printf("could not load image... ");

                      return -1;

             }

             namedWindow("input", CV_WINDOW_AUTOSIZE);

             imshow("input", src);

             // 直接读取图像像素

             int height = src.rows;

             int width = src.cols;

             int ch = src.channels();

             for (int c = 0; c < ch; c++) {

                      for (int row = 0; row < height; row++) {

                              for (int col = 0; col < width; col++) {

                                       if (ch == 3) {

                                                Vec3b bgr = src.at<Vec3b>(row, col);

                                                bgr[0] = 255 - bgr[0];

                                                bgr[1] = 255 - bgr[1];

                                                bgr[2] = 255 - bgr[2];

                                                src.at<Vec3b>(row, col) = bgr;

                                       } else if(ch == 1) {

                                                int gray = src.at<uchar>(row, col);

                                                src.at<uchar>(row, col) = 255 - gray;

                                       }

                              }

                      }

             }

             imshow("output", src);

             waitKey(0);

             return 0;

    }

    后知后觉、越学越菜
  • 相关阅读:
    roportional Rate Reduction (PRR)
    【C++11新特性】 nullptr关键字
    C++ 智能指针
    std::thread
    C++11 的 std::ref 用法
    for auto
    C++11右值引用与移动构造函数
    leetcode刷题笔记一百零六题 从中序与后序遍历序列构造二叉树
    leetcode刷题笔记一百零五题 从前序与中序遍历序列构造二叉树
    leetcode刷题笔记一百零四题 二叉树的最大深度
  • 原文地址:https://www.cnblogs.com/chenhuanting/p/10830129.html
Copyright © 2011-2022 走看看