opencv图像操作_查看图像通道数与像素信息
头文件
#include<iostream>
#include<opencv2\opencv.hpp>
using namespace std;
using namespace cv;
文件读取并转换为灰度图
int main()
{
Mat src,gray;
src = imread("C:\\Users\\dell\\Desktop\\ss\\1.jpg");
//namedWindow("img");
imshow("img", src);
cvtColor(src, gray, CV_BGR2GRAY);
imshow("gray", gray);
waitKey(0);
return 0;
}
查看通道数
cout << "img channels:" << src.channels();
cout << "\ngraychannels:" << gray.channels();
查看像素
int cols, rows;
cols = gray.cols;
rows = gray.rows;
cout << "\ncols:" << cols;
cout << "\nrows:" << rows;
uchar* firstRow = gray.ptr<uchar>(0);//获取像素值
printf("\nfirst pixel:%d\n", *firstRow);
//uchar firstRow = gray.at<uchar>(0);//获取像素值
//printf("\nfirst pixel:%d\n", firstRow);