<p>I highly recommend you to use <a href="https://pypi.org/project/mss/" rel="noreferrer">MSS</a> instead of cv2 to capture the screen. cv2 is useful to handle image data, but no good at capturing. On the other hand, mss runs much faster than any other screen capture APIs. I used mss to apply object detection(<a href="https://arxiv.org/pdf/1612.08242.pdf" rel="noreferrer">YOLOv2</a>, <a href="https://github.com/thtrieu/darkflow" rel="noreferrer">darkflow</a>), and it run at over 40 frames per second. If it is used without any object detection, it should run at more fps. Here is the script:</p>

<pre><code>import numpy as np
import cv2
import glob
from moviepy.editor import VideoFileClip
from mss import mss
from PIL import Image
import time

color = (0, 255, 0) # bounding box color.

# This defines the area on the screen.
mon = {'top' : 10, 'left' : 10, 'width' : 1000, 'height' : 800}
sct = mss()
previous_time = 0
while True :
    sct.get_pixels(mon)
    frame = Image.frombytes( 'RGB', (sct.width, sct.height), sct.image )
    frame = np.array(frame)
    # image = image[ ::2, ::2, : ] # can be used to downgrade the input
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    cv2.imshow ('frame', frame)
    if cv2.waitKey ( 1 ) &amp; 0xff == ord( 'q' ) :
        cv2.destroyAllWindows()
    txt1 = 'fps: %.1f' % ( 1./( time.time() - previous_time ))
    previous_time = time.time()
    print txt1
</code></pre>
How to Capture Screen using Python with better frame rate
<p>So i have this code, which records my screen and saves it as output.avi
but it only captures 10-15 frames per second. How do i make it capture around 50-60 frames at least. if i am not wrong cv2 is cpu based or something. how do i use gpu to do this task ?</p>

<pre><code>import cv2
from PIL import ImageGrab
import numpy as np

fourcc = cv2.VideoWriter_fourcc('X','V','I','D')
video = cv2.VideoWriter("output.avi",fourcc,8,(1920,1080))

while(True):
    image = ImageGrab.grab()
    image = np.array(image)
    frame = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    video.write(frame)
    key = cv2.waitKey(1)
    cv2.imshow("Hello",frame)
    if(key==27):
        break
video.release()
cv2.destroyAllWindows()
</code></pre>