Opencv C++成长之路(七):RGB转换灰度图像

版权声明:——转载请留言询问—— https://blog.csdn.net/weixin_44344462/article/details/88743965

转换结果

原图像
在这里插入图片描述
灰度图像
在这里插入图片描述

Show me the code

#include <iostream>
#include <string>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui.hpp>

using namespace std;

int main() {
    // 图像路径
    const string fileName = "xxx.jpg";
    
    // 读取图像
    cv::Mat origin = cv::imread(fileName);
    
    // 开辟result存放结果
    cv::Mat result;
    
    // RGB转换成GRAY
    cv::cvtColor(origin,
                 result,
                 cv::COLOR_BGR2GRAY);
    
    // 显示原图像与结果
    cv::imshow("Origin Image", origin);
    cv::imshow("Result", result);
    
    cv::waitKey(0);
}

猜你喜欢

转载自blog.csdn.net/weixin_44344462/article/details/88743965