Computer/Coding

[opencv] C++ 이미지 파일 열기

순박한시골청년 2021. 1. 4. 15:46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
 
#include "opencv2/highgui.hpp"
#include "opencv2/core.hpp"
 
using namespace cv;
using namespace std;
 
int main() 
{
    // init mat
    Mat img, grayImg;
 
    // load image
    img        = imread("이미지 파일 경로", cv::IMREAD_COLOR);
    grayImg = imread("이미지 파일 경로", cv::IMREAD_GRAYSCALE);
 
    // check image
    if (img.empty() || grayImg.empty())
    {
        cout <<"image loading fail" << std::endl;
        return -1;
    }
 
    // show image
    imshow("ori image", img);
    imshow("gray image", grayImg);
 
    // wait
    waitKey(0);
 
    return 0;
}
cs