Opencv C++:在应用颜色图之前使用图像的光标显示像素值

Opencv C++: Display pixel value using cursor of the image before applying colormap

我为这个令人困惑的标题道歉。基本上我想在应用颜色图之前使用鼠标光标显示图像的像素值。是否可以?我知道如何从 here 获取 (x,y) 坐标 这是我的代码:

cv::Mat falseColorsMap;
void onMouse( int event, int x, int y, int, void* );
void showImage( cv::Mat frameMat){
    double min;
    double max;
    cv::minMaxLoc(frameMat, &min, &max);
    std::cout << min << "," << max << "\n";

    cv::Mat adjMap;
    frameMat.convertTo(adjMap,CV_8UC1, 255 / (max-min), -min); // expand your range to 0..255. Similar to histEq();
    applyColorMap(adjMap, falseColorsMap, cv::COLORMAP_JET);


    namedWindow( "Out", CV_WINDOW_NORMAL );// Create a window for display.
    resizeWindow("Out", 800, 600);
    setMouseCallback( "Out", onMouse, 0 );
    cv::imshow("Out", falseColorsMap);
    waitKey(0);
}

// Function onMouse displays cursor values
void onMouse( int event, int x, int y, int, void* )
{
    if ( event != CV_EVENT_LBUTTONDOWN )
        return;

    Point pt = Point(x,y);
    std::cout<<"("<<pt.x<<", "<<pt.y<<") ...... "<<(falseColorsMap.at<int>(y,x)) << '\n';
}

如何在使用鼠标时获取frameMat的像素值?感谢您的帮助!

请查看以下更改以显示颜色图转换前的原始帧像素值。这里添加了基于颜色通道的条件。如果是三通道 (BGR) 图像,它将显示 3 通道像素值,如果是单通道图像,它也会显示像素值:

    cv::Mat falseColorsMap;
    cv::Mat framesMap;
    void onMouse( int event, int x, int y, int, void* );
    void showImage( cv::Mat frameMat){
        double min;
        double max;
        cv::minMaxLoc(frameMat, &min, &max);
        std::cout << min << "," << max << "\n";

        framesMap = frameMat.clone();
        cv::Mat adjMap;
        frameMat.convertTo(adjMap,CV_8UC1, 255 / (max-min), -min); // expand your range to 0..255. Similar to histEq();
        applyColorMap(adjMap, falseColorsMap, cv::COLORMAP_JET);


        namedWindow( "Out", CV_WINDOW_NORMAL );// Create a window for display.
        resizeWindow("Out", 800, 600);
        setMouseCallback( "Out", onMouse, 0 );
        cv::imshow("Out", falseColorsMap);
        waitKey(0);
    }

    // Function onMouse displays cursor values
    void onMouse( int event, int x, int y, int, void* )
    {
        if ( event != CV_EVENT_LBUTTONDOWN )
            return;

        Point pt = Point(x,y);

if(framesMap.channels()==3)
{
        std::cout<<"("<<pt.x<<", "<<pt.y<<") ...... [blue] "<<framesMap.at<Vec3b>(y,x)[0] << " [green] "<<framesMap.at<Vec3b>(y,x)[1] << " [red] "<<framesMap.at<Vec3b>(y,x)[2]<<'\n';
}
else
{
    std::cout<<"("<<pt.x<<", "<<pt.y<<") ......  "<<framesMap.at<uchar>(y,x) <<'\n';
}
    }