I am starting with the basics of image processing and I am trying to convert a RGB image into grey scale using averaging.
My code is
#include<opencv2/core/core.hpp> #include<opencv2/highgui/highgui.hpp> #include<opencv2/imgproc/imgproc.hpp> #include<iostream> using namespace cv; int main() { Mat image = imread("a.jpg"); namedWindow("Original "); namedWindow("Grey"); imshow("Original", image); Mat grey; std::cout << "hello\n"; for (int i = 0; i < image.rows; i++) { for (int j = 0; j < image.cols; j++) { grey.at<Vec3b>(i, j) = (image.at<Vec3b>(i, j)[0] + image.at<Vec3b>(i, j)[1] + image.at<Vec3b>(i, j)[2]); } } imshow("Grey", grey); return 0; }` I think there is some problem with the Mat Grey , while accessing the element inside the for loop.