#include <opencv2/opencv.hpp>

using namespace cv;


#include <iostream>

using namespace std;


#define STR_WINDOW "Window"


void mouseEvent(int evt, int x, int y, int flags, void *param){

Mat *img = (Mat *)param;

if ( evt == CV_EVENT_LBUTTONDOWN ){

printf("(%04d, %04d) : %03d, %03d, %03d\n", x, y,

(int)(*img).at<Vec3b>(y,x)[0],

(int)(*img).at<Vec3b>(y,x)[1],

(int)(*img).at<Vec3b>(y,x)[2]);

}

}


int main(){

Mat image = imread( your image path );

if ( image.empty() ){

cout << "Error loading the image" <<endl;

return -1;

}


namedWindow(STR_WINDOW, 1);

setMouseCallback(STR_WINDOW, mouseEvent, &image);

imshow(STR_WINDOW, image);


waitKey(0);

return 0;

}


<< result >>

+ Recent posts