1

I used to be able to hover the mouse over the displayed image and get the pixel value in real time at the bottom of the window.

I am not sure why is that not working anymore, I use Python 3.9.7 and OpenCV 4.5.5 on windows 10, is there a specific version of python+oopencv where that works?

import cv2

img = cv2.imread("testImage.jpg")
cv2.imshow("img", img )
cv2.waitKey()
cv2.destroyAllWindows()

It is now missing from the bottom

fmw42
  • 46,825
  • 10
  • 62
  • 80
Joseph Adam
  • 1,341
  • 3
  • 21
  • 47
  • I am on Python 3.7, cv2 version 4.5.5, linux and it works for me – S P Sharan Jan 20 '22 at 17:19
  • Check this out: https://stackoverflow.com/q/62870031/8878627 – S P Sharan Jan 20 '22 at 17:21
  • @SPSharan downgraded to 3.7.9 , still same issue. Tried downloading using `pip install opencv-contrib-python` and `pip install opencv-python` still same issue. – Joseph Adam Jan 20 '22 at 17:24
  • 3
    I think you need a build of OpenCV which is compiled with Qt as the HighGUI backend. The standard ones on Windows use WinAPI, and all you get with `imshow` is just a window frame with a title. Version doesn't matter, i have about 15 starting from 2.4.x up to current ones, all act the same. – Dan Mašek Jan 20 '22 at 17:31
  • thanks @DanMašek I see a few tutorials online that does CUDA + CUDNN + QT and so on. Are there other less complex ways or a command that does this? – Joseph Adam Jan 20 '22 at 18:13
  • just set a mouse callback. then you can print the coordinates on the command line – Christoph Rackwitz Jan 20 '22 at 19:29
  • @ChristophRackwitz updated the answer, you cannot zoom in though :/ – Joseph Adam Jan 20 '22 at 19:59

1 Answers1

-1

@Christoph suggested a callback which is here, but you cannot zoom into the image

import cv2


def mouse_callback(event, x, y, flags, params):
    if event == 2:
        print(f"coords {x, y}, colors Blue- {img[y, x, 0]} , Green- {img[y, x, 1]}, Red- {img[y, x, 2]} ")


img = cv2.imread("testImage.jpg")

cv2.namedWindow("image")
cv2.setMouseCallback("image", mouse_callback)

cv2.imshow("image", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Joseph Adam
  • 1,341
  • 3
  • 21
  • 47