imread(“图像所在的路径”,图像显示的模式) :读取图像
namedWindow(“窗口名”, 窗口模式);
imshow(“窗口名”, 读取的图像名);
cvtColor(输入图像名, 输出图像名, COLOR_BGR2GRAY);
方法一:
#include
#include <opencv2/opencv.hpp>
#include <math.h>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat src = imread(“E:/Learning_AI/OpenCV_C++/1.jpg”); //读取图像
if (src.empty())
{
cout << “could not load image…” << endl;
return 0;
}
namedWindow(“input”, WINDOW_NORMAL);
imshow(“input”, src);
/图像灰度画部分/
Mat dst;
namedWindow(“output”, WINDOW_NORMAL);
cvtColor(src, dst, COLOR_BGR2GRAY); //图像灰度化
imshow(“output”, dst);
waitKey(0); //
return 0;
}
方法二:
//该方法缺陷较多,只满足打开图像
#include
#include <opencv2/opencv.hpp>
#include <math.h>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat src = imread(“E:/Learning_AI/OpenCV_C++/1.jpg”,IMREAD_GRAYSCALE);
imshow(“input”, src);
waitKey(0);
return 0;
}