I'm running a neural network on a live stream of screenshots 800x600 in size. Since I was only getting about 3fps, I did some troubleshooting and found out how much time is approximately spent on each step:
- Screenshot: 12ms
- Image processing: 280ms
- Object detection and box visualisation: 16ms
- Displaying image: 0.5ms
I'm using mss for taking the screenshots (documentation).
Here's the code without the object detection part:
import numpy as np
import cv2
from PIL import Image
import mss
monitor = {"top": 40, "left": 0, "width": 800, "height": 600}
with mss.mss() as sct:
while True:
# # Screenshot:
image = sct.grab(monitor)
# # Image processing:
image = Image.frombytes("RGB", image.size, image.bgra, "raw", "RGBX")
(im_width, im_height) = image.size
image_np = np.array(image.getdata()).reshape((im_height, im_width, 3)).astype(np.uint8)
# # Object detection and box visualisation:
# ...
# # Displaying image:
cv2.imshow("Object Detection", image_np)
Any ideas on how I can make this quicker?