标签:named 目录 wait containe core out turn png har
#include <opencv2/opencv.hpp> //总的头文件
// #include <opencv2/core.hpp>
// #include <opencv2/imgcodecs.hpp>
// #include <opencv2/highgui.hpp>
#include <iostream>
#include <string>
int main(int argc, char** argv)
{
std::string image_name = "/home/liuzhiyang/test/color_image.png";
cv::Mat color_image;
color_image = cv::imread(image_name, cv::IMREAD_COLOR);
if (color_image.empty())
{
std::cout << "fail to read image!" << std::endl;
return 0;
}
cv::namedWindow("color_image");
cv::namedWindow("gray_image");
cv::Mat gray_image;
cv::cvtColor(color_image, gray_image, cv::COLOR_BGR2GRAY);
cv::imshow("color_image", color_image);
cv::imshow("gray_image", gray_image);
cv::waitKey(0);
cv::imwrite("/home/liuzhiyang/test/gray_image.png", gray_image);
return 0;
}
注: 读取灰色图像
cv::imread(filename, IMREAD_GRAYSCALE);
标签:named 目录 wait containe core out turn png har
原文地址:https://www.cnblogs.com/chrislzy/p/14940161.html