1
  1. there are more than 24 thousand 2d (x,y) and 3d (x3d,y3d,z3d) points
  2. points are sorted in a database each with a label ... there are three type of labels (A , B, C)
  3. each label has a matching image
  4. all the rows are sorted by time

I need to animate these files as a video after plotting the 2d points as a box.

This code saves the images but that takes a lot of time and has failed two times.

ima = np.array(Image.open('a.png'), dtype=np.uint8)
imb = np.array(Image.open('b.png'), dtype=np.uint8)
imc = np.array(Image.open('c.png'), dtype=np.uint8)

# Create figure and axes
fig,ax = plt.subplots(1)
patch = patches.Rectangle((0, 0), 0, 0, fc='y')

for i in range(bb_2d_br_y.count()):
    # Create figure and axes
    fig,ax = plt.subplots(1)
    height =  bb_2d_br_y[i] - bb_2d_tl_y[i]

    weidth =  bb_2d_br_x[i] - bb_2d_tl_x[i]

    # Create a Rectangle patch
    rect = patches.Rectangle((centre_2d_x[i], centre_2d_y[i]), weidth, height, linewidth=1,
                             edgecolor='r', facecolor='none')

    if locations[i] == 'a':
        ax.imshow(ima)
    elif locations[i] == 'b':
        ax.imshow(imb)
    else: #c
        ax.imshow(imc)

    # Add the patch to the Axes
    ax.add_patch(rect)

    fig.savefig(my_path + '/graph' + str(i) + '.png')
  • The question [**_How to animate a time-ordered sequence of matplotlib plots_**](http://stackoverflow.com/questions/6686550/how-to-animate-a-time-ordered-sequence-of-matplotlib-plots) has some suggestions. – martineau Apr 26 '17 at 00:18
  • i tried different solutions but i still have the same problom, do you have any suggestion to do this work, library or another programming language? – Rabab Ahmad Apr 26 '17 at 21:19
  • You've never really said what the failures where. If the images can be converted to GIF, the PIL module is capable of creating animated GIF files. So can the free third-party ImageMagick package (which has a Python binding named PythonMagick). There are animated GIF to MP4 video converts available. Regardless of how you do it, processing 24K images is going to take a relatively long time. – martineau Apr 26 '17 at 21:38

1 Answers1

0

Unfortunately couldn't find any other solution except the one provided above and keep creating the photos series and whenever my computer crashs I change the starting range ex.

 range(x, bb_2d_br_y.count())

x is my last created index

then I created a (bad , i think) resolution video but fast enough using ffmpeg library from this post

Python: Make a video using several .png images

using

 ffmpeg -f image2 -r 24 -i graph%d.png -vcodec mpeg4 -y movie.mp4
Community
  • 1
  • 1