Matplotlib set_array slow in comparison with cv2

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.

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...

Cheers!
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
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160417/bab135a7/attachment.html&gt;

Which version of matplotlib are you using?
which backend is in use,

I use python 3.4 with Anaconda; I believe that the version of Matplotlib is
1.4.3

Also, it would be good to know what your benchmark results are.

The images are 1920x1200 = 1.94MB, and I am trying to run this at 10 fr/s:
Matplotlib can't, while opencv can run this at 30 fr/s without problem. Even
for smaller images, there is a notable difference.

My question is: have you tried the code I've posted, and is it running fine
for you ?

thx.

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Matplotlib-set-array-slow-in-comparison-with-cv2-tp46938p46971.html
Sent from the matplotlib - users mailing list archive at Nabble.com.