Skip to content

Instantly share code, notes, and snippets.

@umanda
Created February 20, 2020 12:56
Show Gist options
  • Save umanda/3e00035efebc4500e29689b9115bc045 to your computer and use it in GitHub Desktop.
Save umanda/3e00035efebc4500e29689b9115bc045 to your computer and use it in GitHub Desktop.
RGB to Gray scale Image - OpenCV
/*
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