opencv 訪問彩色圖片畫素(指標方法)
阿新 • • 發佈:2018-12-09
#include "stdafx.h" #include <cv.h> #include <highgui.h> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> #include <vector> using namespace cv; using namespace std; void RemoveSmallRegion(Mat& Src, Mat& Dst, int AreaLimit = 50, int CheckMode = 1, int NeihborMode = 0); int main() { Mat SrcImage = imread("11.png"); namedWindow("原圖", 2); imshow("原圖", SrcImage); int height = SrcImage.rows; int width = SrcImage.cols; //cout << height << " " << width <<endl; //指標訪問陣列 for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { //取出圖片第i行第j列的畫素 uchar *p = SrcImage.ptr<uchar>(i,j); if (i == j) //當i=j時 將畫素賦值為紅色 { p[0] = 0; p[1] = 0; p[2] = 255; } } } namedWindow("處理圖", 1); imshow("處理圖", SrcImage); waitKey(0); return 0; }
結果顯示: