From eb3969e244cafa98c44574d7d1b3e7213c490c4b Mon Sep 17 00:00:00 2001 From: Jan Gaura Date: Wed, 14 Mar 2018 13:27:11 +0100 Subject: [PATCH] Better text contrast of pixel brightness values in Qt window This offsets text brightness of pixel brightness values by offsetting it by 127 to the curent pixel value. The text is now readable even if pixels are black. --- modules/highgui/src/window_QT.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/highgui/src/window_QT.cpp b/modules/highgui/src/window_QT.cpp index 68d91a2e21..5faf530d33 100644 --- a/modules/highgui/src/window_QT.cpp +++ b/modules/highgui/src/window_QT.cpp @@ -3094,6 +3094,11 @@ void DefaultViewPort::drawImgRegion(QPainter *painter) if (nbChannelOriginImage==CV_8UC1) { QString val = tr("%1").arg(qRed(rgbValue)); + int pixel_brightness_value = qRed(rgbValue); + int text_brightness_value = 0; + + text_brightness_value = pixel_brightness_value > 127 ? pixel_brightness_value - 127 : 127 + pixel_brightness_value; + painter->setPen(QPen(QColor(text_brightness_value, text_brightness_value, text_brightness_value))); painter->drawText(QRect(pos_in_view.x(),pos_in_view.y(),pixel_width,pixel_height), Qt::AlignCenter, val); }