0

I am trying to learn about Opencv on embeded Linux. Currently I am working on NXP i.mx8m.

I used VS code in remote SSH. The first target is to display an image and destroy the window when pressed key "q", like usual.

import numpy as np
import cv2

img = cv2.imread('L5.jpeg')
cv2.imshow('Window name', img)

key =cv2.waitKey(0)
print(key)

if key== ord('q'):
   print("pressed q")

cv2.destroyAllWindows()

The window of imshow GUI appears on the monitor which connected to I.mx8m, as wished.

BUT simply waitkey(0) doesn't respond. The window is there. The return value of cv2.waitKey(0) is always -1, no matter which key I press. I can only stop the program by Ctr+Z.

I have learned that , If I run the code on local system, it works only when the GUI window is in focus. But in a remote SSH, how can I put the HiGUI in focus?

I searched google many times, but still cannot find the solution. can anyone be so kind and help me?

I sense maybe I missed some configuration in SSH?

Thousand thanks!

regards Cliff

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
yzhuad
  • 3
  • 1
  • your waitkey should be in a loop and listen the keyboard continuously. this code works in your locak ? i think it will now. any key you press after `imshow` it ll disappear. – Yunus Temurlenk Aug 04 '22 at 06:37
  • Hi Yunus, thanks very much for reply. this code only works when I run this code in my local computer. but when I run the same on embedded Linux device, it doesn't work. the return value of cv2.waitKey(0) is never passed to parameter Key. and the print(key) line never print. That is why I know for sure if "key== ord('q'): print("pressed q")" also didn't run. – yzhuad Aug 04 '22 at 20:01
  • How does the window stuff work in your ssh/vs-code environment? X-Forwarding? – Micka Aug 05 '22 at 11:04
  • Is it similar to this? https://bbs.archlinux.org/viewtopic.php?id=134921 – Micka Aug 05 '22 at 11:10
  • Or this one? https://unix.stackexchange.com/questions/509179/in-x11-ssh-forwarding-keyboard-isnt-working-properly-only-ctrl-and-numer – Micka Aug 05 '22 at 11:12
  • I have not used any X11 or window forwarding. first time heard of it. Maybe this is the reason. I need to have a try. much thanks – yzhuad Aug 08 '22 at 20:58
  • 1
    @Micka, I have installed the XQuatz and enabled X11forwarding in vscode, now it works fine! – yzhuad Aug 08 '22 at 21:49

0 Answers0