Created
February 20, 2020 12:56
-
-
Save umanda/3e00035efebc4500e29689b9115bc045 to your computer and use it in GitHub Desktop.
RGB to Gray scale Image - OpenCV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
author : Umanda Jayobandara | |
*/ | |
#include <iostream> | |
#include <opencv2/core/core.hpp> | |
#include <opencv2/highgui/highgui.hpp> | |
#include <opencv2/imgproc/imgproc.hpp> | |
using namespace std; | |
using namespace cv; | |
int main(int argc, char** argv) { | |
String imgName = "umanda.jpg"; | |
cv::String window_original = "original image"; | |
cv::String window_gray = "gray image"; | |
cv::Mat img = cv::imread(imgName); | |
if (img.empty()) | |
std::cout << "failed to open img.jpg" << std::endl; | |
else | |
std::cout << "img.jpg loaded OK" << std::endl; | |
cv::Mat grayMat; | |
cv::cvtColor(img, grayMat, cv::COLOR_BGR2GRAY); | |
cv::namedWindow(window_original, cv::WINDOW_AUTOSIZE); | |
cv::imshow(window_original, img); | |
cv::namedWindow(window_gray, cv::WINDOW_AUTOSIZE); | |
cv::imshow(window_gray, grayMat); | |
cv::waitKey(0); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment