#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 >>
'STUDY > OpenCV' 카테고리의 다른 글
[OpenCV] 관심영역 자르기 (Crop Region Of Interesting (ROI)) (2) | 2016.08.11 |
---|---|
[OpenCV] 이미지 저장 (save image) (0) | 2016.08.11 |
OpenCV install on Ubuntu (0) | 2015.01.15 |
Ubuntu에서 Opencv2.4.0 설치 및 예제 실행 (0) | 2014.07.15 |
cvCreateTrackbar, On_Change 적용 in Class (0) | 2014.01.14 |