一、運行環境
環境是Visual Studio 2015和OpenCV4.0.1
二、示例代碼
主要涉的函數:
CV_EXPORTS_W void cvtColor( InputArray src, OutputArray dst, int code, int dstCn = 0 );
簡介:該函數將輸入圖像從一種顏色空間轉換爲另一種顏色空間。從而方便的在不同顏色空間下修改圖片。
#include<iostream>
#include<opencv2\opencv.hpp>
using namespace cv;
int main(int argc, char *argv[])
{
const char * imagePath = "./1234.jpg";
const char * savePath = "./result.jpg";
const char * source = "sourceImage";
const char * result = "resultImage";
Mat sourceImage = imread(imagePath);
Mat grayImage;
namedWindow(source);
imshow(source, sourceImage);
cvtColor(sourceImage, grayImage, COLOR_BGR2GRAY);
namedWindow(result);
imshow(result, grayImage);
waitKey(0);
imwrite(savePath, grayImage);
return 0;
}