Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Extract pixel value from Mat not working (for me)

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