[Matplotlib-users] Matplotlib set_array slow in comparison with cv2

Benjamin Root ben.v.root at gmail.com
Sun Apr 17 11:04:33 EDT 2016

Which version of matplotlib are you using? We recently overhauled our image
architecture, so displaying should be faster. There may also be other
issues at play here, such as whether the interactivity mode is on or off,
which backend is in use, and also all of the additional rendering that may
be needed (ticks, plotting area, etc., that opencv may not be handling.

Also, it would be good to know what your benchmark results are. We would be
concerned if there was a significant difference in performance (orders of
magnitude), but it isn't like we are aiming for doing playback of 4K videos
at 100fps, either...

Ben Root

On Mon, Apr 4, 2016 at 4:24 PM, coquelicot <coquelicot at walla.com> wrote:

> Compare the following 2 codes:
>     import matplotlib.pyplot as plt
>     import cv2
>     def grab_frame(i): #this function simply grab frame i from an image
> folder or a video
>         ...
>         return img_array_like_returned_by_imread_or_cv2.imread
>     #remove the following two lines to test with opencv:
>     fr = grab_frame(0)
>     img = plt.imshow(fr)
>     for i in range(0,300):
>         fr = grab_frame(i)
>             img.set_array(fr)
>             plt.pause(0.001)
>             #replace the previous 2 lines by the following 2 lines to
>             #compare with opencv:
>             #cv2.imshow('frame', fr)
>             #if cv2.waitKey(1) & 0xFF == ord('q'): break
> My questions are:
>  1) why is set_array much slower than cv2.imshow ?
>  2) is it possible to improve this, say by tricking some function of
> matplotlib ?
> --
> View this message in context:
> http://matplotlib.1069221.n5.nabble.com/Matplotlib-set-array-slow-in-comparison-with-cv2-tp46938.html
> Sent from the matplotlib - users mailing list archive at Nabble.com.
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160417/bab135a7/attachment.html>

More information about the Matplotlib-users mailing list