#include <opencv2/opencv.hpp> #include <iostream> #include <math.h> using namespace cv; using namespace std; int main() { //原图 Mat src1 = imread(".//pic//test.jpg",IMREAD_UNCHANGED); //灰度图 Mat src2 = imread(".//pic//test.jpg", IMREAD_GRAYSCALE); //RGB图 Mat src3 = imread(".//pic//test.jpg", IMREAD_COLOR ); if (src1.empty() || src2.empty() || src3.empty()) { cout << "找不到图像" << endl; return -1; } namedWindow("opencv startup", CV_WINDOW_AUTOSIZE); imshow("原图", src1); imshow("灰度图", src2); imshow("RGB图", src3); //转化成灰度图 Mat output; /*cvtColor(src3, output, CV_BGR2GRAY); imshow("RGB图", src3); imshow("RGBTo灰度", output);*/ //颜色空间转换 cvtColor(src3, output,CV_BGR2HLS); imshow("RGB图", src3); imshow("颜色空间转换", output); //图像保存 imwrite("./store.png", output); waitKey(); return 0; }
原文地址:https://www.cnblogs.com/xiaochi/p/11990975.html
时间: 2024-10-11 10:17:20