0

I am trying to run this piece of code. But the problem is it never comes out of the loop.I am able to close the window but it pop back again I don't know why is happening? is it the problem with my installations or any error.

python version:3.6 opencv version:4.2.0.34

 import numpy as np
 from PIL import ImageGrab
 import cv2
 import time
 while(True):
         
        printscreen =  np.array(ImageGrab.grab(bbox=(0,40,800,640)))
        last_time = time.time()
        print('loop took {} seconds'.format(time.time()-last_time))
        
        cv2.imshow('window',cv2.cvtColor(printscreen, cv2.COLOR_BGR2RGB))
        if cv2.waitKey(25) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            break 
Ali
  • 687
  • 8
  • 27
Time
  • 97
  • 8
  • that pgm will generate an error last times is used before initiating! – Ali Oct 28 '20 at 15:48
  • Does this answer your question? [Closing video window using close "X" button in OpenCV, Python](https://stackoverflow.com/questions/13307606/closing-video-window-using-close-x-button-in-opencv-python) – steviestickman Oct 28 '20 at 15:57
  • your code is missing a few lines but with them added it works fine if the mouse's focus is on the image – DrBwts Oct 28 '20 at 16:40
  • I had to press q to stop the loop and close the window. – Time Oct 31 '20 at 15:25

0 Answers0