• DepthAI
  • Quitting when running in console without vis window

How do I make it so that I can quit out of a running script in the console when there is no visualization window open without using CTRL-C? If the vis window is up I just hit Q, but if it is outputting to stdout it just keeps looping forever until I manually break it.

from depthai_sdk import OakCamera
import time

def cb(packet):
    print('looping is fun')
    time.sleep(1)

with OakCamera() as oak:
    color = oak.create_camera('color')
    nn = oak.create_nn('yolov6nr3_coco_640x352', color)

    oak.callback(nn, callback=cb)
    oak.start(blocking=True)

Thanks

    Hi vital
    You can exit the program with a key when cv2 window is open, because the oak is constantly running the cv2.waitkey() function which expects a "Q" key press.
    You should be able to do the same without cv2 by putting a similar function into a callback of the camera. Just something to check whether a key has been detected.

    Thanks,
    Jaka

      jakaskerl

      Doesn't work. What am I doing wrong?

      from depthai_sdk import OakCamera
      import time
      
      def cb(packet):
          print('looping is fun')
          time.sleep(1)
      
      with OakCamera() as oak:
          color = oak.create_camera('color')
          nn = oak.create_nn('yolov6nr3_coco_640x352', color)
      
          oak.callback(nn, callback=cb)
          oak.start()
      
          while oak.running:
              key = oak.poll()
              if key == ord('q'):
                  break

        Hi vital
        Opencv won't be able to detect a key press unless a window is open. I meant running some other keylogger function inside the cb function instead of opencvs waitkey().

        Thanks,
        Jaka

          vital If the vis window is up I just hit Q, but if it is outputting to stdout it just keeps looping forever

          I hover the mouse cursor over the CV display window and hit 'q' to stop the python program.