OpenCV simple showimage command takes 70ms on RPI4

asked 2020-07-13 03:36:48 -0500

Dear OpenCV-Fellows, I am using openCV on a RPI4 - 4GB and I'm doing realtime person detection with it so frame rate is quite crucial. My whole alogrithm takes 70ms and then, on top, the showimage takes again 70ms, which basically halfs the framerate.

Can you think of a way to speed up the imageshow? Currently, I am using a 1920x1080png with a size of around 1MB. I update only a few numbers on the image during each cycle.

def showimage(img):
    to_show = img.copy()
    cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
    cv2.putText(to_show, str(allowed), (180, 660), cv2.FONT_HERSHEY_SIMPLEX, 10, (255, 255, 255), 15)
    cv2.putText(to_show, str(people_inside), (180, 1020), cv2.FONT_HERSHEY_SIMPLEX, 10, (255, 255, 255), 15)
    cv2.imshow("window", to_show)
edit retag flag offensive close merge delete


I see two possibilities:

  • use your own functions for rendering using low-level API calls, e.g. GTK, X11, OpenGL, ...
  • render in another thread, but you will have some delay
Eduardo gravatar imageEduardo ( 2020-07-13 07:10:52 -0500 )edit

Thank you Eduardo, do you have some tutorial in mind that explains your suggestion: using low-level API calls, e.g. GTK, X11, OpenGL,

I have no idea where to start and there aren't helpful google entries for that keywords.

Markovicz gravatar imageMarkovicz ( 2020-07-13 14:37:56 -0500 )edit

You should try first to render in another thread.

Also, you should try to display the bare minimum, that is imshow + waitKey and without any processing to see the computation time and if the other calls would not be the source of the slowdown.

Since you are using Python, you can try PyQt. I think there should be also tutorials for using OpenGL in Python.

Eduardo gravatar imageEduardo ( 2020-07-13 22:45:56 -0500 )edit