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;

    }

    后知后觉、越学越菜
  • 相关阅读:
    一款非常推荐的用户界面插件----EasyUI
    使用chart和echarts制作图表
    JS模拟实现封装的三种方法
    JavaScript面向对象(OOP)
    移动HTML5前端框架—MUI
    一款优秀的前端JS框架—AngularJS
    less和scss
    JS中的正则表达式
    JS中的数组
    js匿名函数
  • 原文地址:https://www.cnblogs.com/chenhuanting/p/10830129.html
Copyright © 2011-2022 走看看