How to get letter from keyboard

Hi how close the streaming with key like

if cv2.waitKey(25) & 0xFF==ord('q'):

i want to close this stream while hit a button

import jetson.inference
import jetson.utils
import time

net = jetson.inference.detectNet("ssd-mobilenet-v2", threshold=0.5)
camera = jetson.utils.videoSource("/dev/video1")      # '/dev/video0' for V4L2
display = jetson.utils.videoOutput("") # 'my_video.mp4' for file

while display.IsStreaming():
	img = camera.Capture()
	detections = net.Detect(img)
	display.SetStatus("Object Detection | Network {:.0f} FPS".format(net.GetNetworkFPS()))

when import cv2 to Streaming code that @dusty_nv share, it doesn’t run

Hi @savunmasad, you can import cv2 after the display = jetson.utils.videoOutput(""), and it should still create the OpenGL window then. It seems that when cv2 is imported, it loads a conflicting GL/GLX extension manager, but if the window is created beforehand it’s fine.

By default, the window will close when you press the Escape key. If you want to change that key, you can do so on this line of code from jetson-inference/utils/display/glDisplay.cpp:1305

If you make a change in the C++ code, re-compile and re-install it with these steps:

$ cd jetson-inference/build
$ make
$ sudo make install

Thank you.
By the way how can i add new features for example

Save the video pressing a key or etc.

Unfortunately I don’t have the event handling exposed via the Python bindings, so you would add them to the C++ version of the handler, or you could use cv2.waitKey() if you can get that working.

Alternatively, you could use another Python library to get the keyboard input. In the past I have used the pynput library:

1 Like