OpenCV slow on retina screen vs external screen

asked 2016-12-13 03:30:51 -0600

I have noticed a really weird behaivor of OpenCV on my Macbook 12 retina (Early 2015 model). I am using OpenCV 3.1.0 and Python 3.5.1 on Mac OSX El Capitan 10.11.2

When I put a window in the external screen (27" 1920x1080) the code runs fast but when I take the same window and move it to the builtin screen(12" 2304 × 1440 on the default settings) the code runs alot slower.

Here is a minimal code that shows the problem:

import cv2
import numpy as np
from time import time, sleep


sum_time = 0
samples = 1000

i = 0

while i < samples:
  zeros = np.zeros((640,480,3), dtype=np.uint8)
  cv2.imshow("Frame", zeros)
  t = time()
  cv2.waitKey(1)
  sum_time += (time() - t)
  i+=1

print("Avg time for  took: %f" % (sum_time / samples))

When running on the external screen I get:

Avg time for  took: 0.015225

When running the exact same code on the retina screen (i.e. the window is being rendered there):

Avg time for  took: 0.033613

I tried it a bunch of times and the results are consistent, any idea what might cause this?

edit retag flag offensive close merge delete

Comments

Well, the retina screen has a lot more pixels, and it might take time for the compositing engine to render your image on the screen. It's not just a matter of plotting values on the screen, but there is also some color correction and DPI enhancement involved on the retina screen. I suppose that takes time

iev6 gravatar imageiev6 ( 2016-12-13 07:30:17 -0600 )edit

Yeha but that much? I mean I can only push 10 fps and in the other screen I can push well over 30 fps... I would assume the GPU would take care of it, maybe the UI facilities in mac aren't accelerated?

urielka gravatar imageurielka ( 2016-12-14 02:25:21 -0600 )edit

It might just be that the imshow function isn't GPU accelerated.

iev6 gravatar imageiev6 ( 2016-12-14 03:17:00 -0600 )edit

any recommended alternative? :)

urielka gravatar imageurielka ( 2016-12-14 07:37:41 -0600 )edit