c++ OpenCV 灰度图

c++ OpenCV 灰度图

#include <iostream>
#include <filesystem>
#include <string>
#include <windows.h>
#include <opencv2/opencv.hpp>

namespace fs = std::filesystem;
using namespace cv;
using namespace std;

int main()
{
    //std::cout << "Hello World!\n";

    //fs::path currentPath = fs::current_path();
    //string filename = currentPath.string() + "\\jzh.png";

    // 图片路径
    string file = "F:/opencv/console/x64/Debug/jzh.png";

    // 显示原图
    Mat src = imread(file);
    imshow("src", src);

    // 灰度
    Mat gray;
    cvtColor(src, gray, COLOR_BGR2GRAY);
    imshow("gray", gray);

    waitKey(0);
    destroyAllWindows();
    return 0;
}

 

发表回复

您的电子邮箱地址不会被公开。