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

转换结果

原图像
Opencv C++成长之路(七):RGB转换灰度图像_第1张图片
灰度图像
Opencv C++成长之路(七):RGB转换灰度图像_第2张图片

Show me the code

#include 
#include 
#include 
#include 

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);
}

你可能感兴趣的:(Opencv-C++成长之路,Opencv灰度图像,图像转换,灰度图像,二值图像)