[Tutor] Speeding up my Python program

aj0358 at web.de aj0358 at web.de
Mon Feb 7 14:53:06 EST 2022


   Hi!
    
   I am pretty new to python, so I thought, this would be a good place to ask
   my question :)
   I am looking for a way to speed up my python program. 
   It contains a simple while-loop, a few print commands and some imports of
   the external libraries PIL and time:
    
   from PIL import ImageGrab
   import time
    
   while end_time < 1:
       start_time=time.time()
       rgb1 = ImageGrab.grab().load()[1185,561]
       rgb2 = ImageGrab.grab().load()[1260,568]
       rgb3 = ImageGrab.grab().load()[1331,571]
       print(rgb1)
       print(rgb2)
       print(rgb3)
       end_time=time.time()-start_time
       print(end_time)
    
   The goal is to analyse every frames of a video (60 fps) and to get the
   pixel colors of three pixels. Unfortunately, at the moment, the programm
   only analyses one frame every (about) 0.5 seconds. 
    
   example Output of the programm:
   (68, 30, 21) 
   (66, 22, 12)
   (129, 78, 28)                          -> pixel colors of the three pixels
   0.4589216709136963              -> time it took to proceed this
   single operation
    
   Now I am looking for a tool to speed up his specific program. Do You have
   any ideas which library or tool to use (I ve heard sth of cython and numpy
   but dont know how they work...)
    
   Thanks for your replies and best regards!
    
   Axel


More information about the Tutor mailing list