1. 程式人生 > >學習c++版opencv3.4之2

學習c++版opencv3.4之2

載入imread,修改cvtColor,儲存imwrite影象。

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;

int main()
{
    Mat src, dst;
    src = imread("/Users/ming/Documents/test.jpg");
    if (src.empty()){
        printf("cannot load the image...");
    }
    namedWindow("src img", CV_WINDOW_AUTOSIZE);
    imshow("src img", src);
    
    cvtColor(src, dst, CV_BGR2GRAY); //bgr to gray
//    cvtColor(src, dst, CV_BGR2RGB); //bgr to rgb
//    cvtColor(src, dst, CV_BGR2HSV);
    namedWindow("gray img");
    imshow("gray img", dst);
    imwrite("/Users/ming/Documents/test_gray.jpg", dst);
    
    waitKey(0);
}