Ask Your Question
0

Tool/Function in OpenCV similar to imtool() in MATLAB

asked 2014-06-04 01:28:40 -0500

updated 2014-06-04 01:51:44 -0500

berak gravatar image

I am looking for a tool similar to imtool() in MATLAB for OpenCV. I want to access the pixel intensity information along with the pixel coordinates, something similar to what imtool() does. When you hover the mouse pointer over an image, it displays the pixel coordinates and the pixel intensity. I have a program for detecting mouse pointer movement here, but I am unable to find any such program for the pixel intensity values. Any suggestions will be appreciated. Thanks.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2014-06-04 01:50:36 -0500

berak gravatar image

using the code from your link, you are already very close.

all it needs now is access to your image in the mouse handler:

// in main:
// Read image from file 
Mat img = imread("MyPic.JPG");
//set the callback function for any mouse event
setMouseCallback("My Window", CallBackFunc, &img); // pass the img address to callback


// callback:
void CallBackFunc(int event, int x, int y, int flags, void* userdata)
{
    Mat img = *((Mat*)userdata); // 1st cast , then deref

    if  ( event == EVENT_LBUTTONDOWN )
    {
        Vec3b pixel = img.at<Vec3b>(y,x); // y,x here !
        cout << "Left button clicked - position (" << x << ", " << y << ")" << endl;
        cout << "color (" << int(pixel[0])  << ", " << int(pixel[1])   << ", " << int(pixel[2])  << ")" << endl;
    }
}
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2014-06-04 01:28:40 -0500

Seen: 1,035 times

Last updated: Jun 04 '14