-1

I am trying to close popup window when i call model.predict using YOLOv8. I want to close window in code only, not using clt+c or q on popup window. Here is my code

import numpy 
import datetime
import imutils
model = YOLO("./Inference_Files/EmptySpace.pt")

file_path= "path_to_video_file"
cap = cv2.VideoCapture(file_path)

while 1:
    # Capture frame-by-frame
    ret, frame = cap.read()
    if ret == True:
    # Display the resulting frame
        #cv2.imshow('Frame', frame)
        res = model.predict(frame,save=True,show=True)

    else:
        cap.release()
        print("video playing is done")
        #cv2.waitKey(0)
        cv2.destroyAllWindows()
cv2.destroyAllWindows()

i tried using cv2.destroyAllWindows() once prediction is done but still popup window will keep alive.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
NIrbhay Mathur
  • 153
  • 1
  • 1
  • 10
  • do you use OpenCV's imshow or do you *not*? looks like `model.predict()` from yolo causes a window, or doesn't it? please clarify. – Christoph Rackwitz Aug 07 '23 at 07:52
  • Yes window is getting open from `yolo.predict`. I dint use OpenCV sepcificaly to open or show results. – NIrbhay Mathur Aug 07 '23 at 08:53
  • 1
    what do you think `show=True` does? do you want this? -- the ultralytics library might be using OpenCV so you _could_ use `cv.destroyWindow(window_name)` if that's the case. HOWEVER that doesn't prevent ultralytics from reopening the window for the next frame. you will have to pass `show=False` then. in any case, it's an ultraltics issue. you should file an issue/feature request. – Christoph Rackwitz Aug 07 '23 at 10:42
  • @ChristophRackwitz, thanks for your reply. i tried `cv.destroyWindow(window_name)`, this dont work in my case. If i do `show=False`, it will not show me inferencing output. Idea is to close popup window when i am running this code in thread. So when i call first inferecning it should pop up and close window and open new popup window when next inferencing thread is called. – NIrbhay Mathur Aug 07 '23 at 11:40
  • By default, yolo doesn't produce windows during prediction. Flag ```show=True``` leads to the method 'show' in the prediction module, which calls ```cv2.imshow()```. The code is [here](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/engine/predictor.py#L275). The results output is regulated by another flag ```verbose=True``` (will output the detection results). Additionally, when does this loop ```while 1``` end? – hanna_liavoshka Aug 09 '23 at 14:19

0 Answers0