1 | initial version |
Hello and thanks to LBerger who made me take into account the row, columns thing. This is the final code:
#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
Mat imageGreen;
static void onMouse(int event, int x, int y, int f, void*){
cout <<(int)imageGreen.at<unsigned char>(y, x) << endl;
}
int main(int argc, char** argv) {
Mat inputImage = imread("/home/diego/Humanoids/imageGreen0.png");
imageGreen = Mat::zeros(inputImage.size(), CV_8UC1);
//Getting the green channel value and putting it into a one channel value.
Vec3b result;
for (int i = 0; i < inputImage.rows ; i++)
{
for (int j = 0; j < inputImage.cols ; j++)
{
result = inputImage.at<cv::Vec3b>(i,j);
int value = result[1];
imageGreen.at<uchar>(i, j) = value;
}
}
cout <<imageGreen.channels()<<endl;
namedWindow( "imageGreen", CV_WINDOW_NORMAL);
imshow("imageGreen", imageGreen);
setMouseCallback("imageGreen", onMouse, 0);
waitKey(0);
return 0;
}