Ask Your Question
0

Extract pixel value from Mat not working (for me)

asked 2019-04-01 10:21:37 -0500

mdresser gravatar image

I am trying to return the value of a specific pixel in a Mat (defined as CV_16UC1, with 12bit monochome data)

This function is passed cursor coordinates as a point with integer .x and .y components. Everything seems to make sense except the returned value which makes no sense at all. I assume something has gone wrong with pointer arithmetic in the "TFrame.at<uint16_t>(TPoint.x(),TPoint.y())" statement but I can't see what I'm doing wrong?

void LT_viewer::temperatureAtCursor(const QPoint & TPoint) {
    double Tmin,Tmax;
    qDebug() << "TFrame.type: " << TFrame.type();
    qDebug() << "TFrame.depth: " << TFrame.depth();
    qDebug() << "TFrame.channels: " << TFrame.channels();
    qDebug() << "TFrame.step1: " << TFrame.step1();
    cv::Size Tsize = TFrame.size();
    qDebug() << "TFrame.size: " << Tsize.width << "x" << Tsize.height;
    cv::minMaxLoc(TFrame,&Tmin,&Tmax);
    qDebug() << "TFrame Min: " << Tmin << ", Max: " << Tmax;
    qDebug() << TFrame.at<uint16_t>(TPoint.x(),TPoint.y()) << " @ " << TPoint.x()<< "," << TPoint.y();
}

The output when I run it looks like this:

Debug:    2019-04-01 11:06:27.411: TFrame.type:  2 
Debug:    2019-04-01 11:06:27.411: TFrame.depth:  2 
Debug:    2019-04-01 11:06:27.411: TFrame.channels:  1 
Debug:    2019-04-01 11:06:27.411: TFrame.step1:  720 
Debug:    2019-04-01 11:06:27.411: TFrame.size:  720 x 540 
Debug:    2019-04-01 11:06:27.412: TFrame Min:  0 , Max:  4095 
Debug:    2019-04-01 11:06:27.412: 65535  @  658 , 251

The output values aren't all 65535 but they don't seem to have any connection with the actual image intensity.

I'd be really grateful for any suggestions of what I'm doing wrong!

Mark

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-04-01 10:24:36 -0500

LBerger gravatar image

updated 2019-04-01 10:25:31 -0500

It is not

TFrame.at<uint16_t>(TPoint.x(),TPoint.y())

but

TFrame.at<uint16_t>(TPoint.y(),TPoint.x())

or

TFrame.at<uint16_t>(TPoint)
edit flag offensive delete link more

Comments

1

Thank you very much for the quick response. I figured I was going to embarrass myself-- I was right! Sometimes it just takes a second set of eyes to see the obvious.

Mark

mdresser gravatar imagemdresser ( 2019-04-01 10:43:57 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-04-01 10:21:37 -0500

Seen: 34 times

Last updated: Apr 01