1 | initial version |
you're close, but there's a few errors:
it is at(y,x)
, not x,y
(row-major)
you have to be strict with the type, xyz.at< short >
is only valid, IF xyz.type() == CV_16S
. for uchar, CV_8U images, it has to be xyz.at< uchar >
, for BGR images xyz.at< Vec3b >
, etc.
2 | No.2 Revision |
you're close, but there's a few errors:your callback function is wrong, you must not try to add another Mat param there, but:
it is
at(y,x)
, not x,y
static void onMouse(int event, int x, int y, int flags, void* param)
{
you also have to be strict with the type, xyz.at< short >
is only valid, IF xyz.type() == CV_16S
. for uchar, CV_8U images, it has to be xyz.at< uchar >
, for BGR images xyz.at< Vec3b >
, etc.
3 | No.3 Revision |
your callback function is wrong, you must not try to add another Mat param there, but:
Mat xyz;
setMouseCallback("cascade_image", onMouse, &xyz);
static void onMouse(int event, int x, int y, int flags, void* param)
{
Mat &xyz = *((Mat*)param); //cast and deref the param
if (event == EVENT_LBUTTONDOWN)
{
short val = xyz.at< short >(y,x); // opencv is row-major !
cout << "x= " << x << " y= " << y << "val= "<<val<< endl;
}
}
you also have to be strict with the type, xyz.at< short >
is only valid, IF xyz.type() == CV_16S
. for uchar, CV_8U images, it has to be xyz.at< uchar >
, for BGR images xyz.at< Vec3b >
, etc.
4 | No.4 Revision |
your callback function is wrong, you must not try to add another Mat param there, but:
Mat xyz;
setMouseCallback("cascade_image", onMouse, &xyz);
&xyz); // pass the address
static void onMouse(int event, int x, int y, int flags, void* param)
param) // you'll get it back in param
{
Mat &xyz = *((Mat*)param); //cast and deref the param
if (event == EVENT_LBUTTONDOWN)
{
short val = xyz.at< short >(y,x); // opencv is row-major !
cout << "x= " << x << " y= " << y << "val= "<<val<< endl;
}
}
you also have to be strict with the type, xyz.at< short >
is only valid, IF xyz.type() == CV_16S
. for uchar, CV_8U images, it has to be xyz.at< uchar >
, for BGR images xyz.at< Vec3b >
, etc.
5 | No.5 Revision |
your callback function is wrong, you must not try to add another Mat param there, but:
Mat xyz;
setMouseCallback("cascade_image", onMouse, &xyz); // pass the address
static void onMouse(int event, int x, int y, int flags, void* param) // you'll get it back now it's in param
{
Mat &xyz = *((Mat*)param); //cast and deref the param
if (event == EVENT_LBUTTONDOWN)
{
short val = xyz.at< short >(y,x); // opencv is row-major !
cout << "x= " << x << " y= " << y << "val= "<<val<< endl;
}
}
you also have to be strict with the type, xyz.at< short >
is only valid, IF xyz.type() == CV_16S
. for uchar, CV_8U images, it has to be xyz.at< uchar >
, for BGR images xyz.at< Vec3b >
, etc.