#include <opencv2\highgui\highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, const char** argv)
{
Mat img = imread("F:\\Image\\6.jpg", CV_LOAD_IMAGE_UNCHANGED); //Mat存储图片
cout << img.rows << endl;
cout << img.cols << endl;
cout << img.dims << endl; //维度
cout << img.channels() << endl; //通道数
if(img.empty())
{
cout << "图像加载失败!"
<< endl;
return -1;
}
//遍历像素点
for (int i = 0; i < img.rows; ++i)
{
for (int j = 0; j < img.cols; ++j)
{
if (img.at<Vec3b>(i, j)[2]>180)
{
img.at<Vec3b>(i, j) = Vec3b(255, 255, 255);
}
}
}
//创建一个名字为MyWindow的窗口
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
//在MyWindow的窗中中显示存储在img中的图片
imshow("MyWindow", img);
//等待直到有键按下
waitKey(0);
//销毁MyWindow的窗口
destroyWindow("MyWindow");
return 0;
}
opencv中Mat存储图像和遍历图像像素
最新推荐文章于 2023-10-08 12:00:39 发布