Python 3 OpenCV Script to Animate Images With Slideshow & Random Transition Using Numpy Desktop App
222 views
Jun 3, 2025
Get the full source code of application here: https://codingshiksha.com/python/python-3-opencv-script-to-animate-images-with-various-animations-using-numpy-gui-desktop-app/
View Video Transcript
0:00
uh hello guys uh welcome to this video
0:02
so in this video I will show you how to
0:04
animate a bunch of images which is
0:06
present inside a directory uh in Open CV
0:10
with multiple transition effects and
0:13
animations let me just launch the
0:15
application right here from the terminal
0:17
so you will see it's a simple Python
0:19
script which will animate all these
0:22
images inside a window with the multiple
0:25
transition effects so let me just launch
0:28
this
0:30
application so now you can see that each
0:33
image will appear for 3 seconds and then
0:36
it will go away with uh random
0:38
transition animation effects it's a
0:41
slideshow you can see it will navigate
0:43
to the next
0:44
image so all these images which are
0:47
present right here in the directory one
0:49
by one each image will appear and as you
0:52
can see you can build out this nice
0:54
little
0:55
slideshow inside the open CV so then
0:59
automatically it will
1:00
close so all the script I have given in
1:03
the description of the video so for
1:05
building this you need quite a uh lot of
1:08
packages so first of all you just need
1:10
to install Open CV
1:14
so Open CV- Python this is the first
1:18
module that you need to
1:20
install secondly you also need the NumPy
1:24
module as
1:26
well so also install this as well i've
1:29
already installed both these modules so
1:32
now I will show you from scratch how to
1:35
build this
1:38
so all the source code will be given in
1:41
the description of the video so first of
1:43
all just you need to require the
1:46
necessary packages so we will require
1:50
the open CV package and numpy 2 numpy
1:56
package as well then we need the
1:59
operating system module the time module
2:02
and the random module as
2:04
well so these are built-in modules
2:08
and after that we need
2:10
to
2:12
actually
2:13
define inside the main
2:19
function so right here we will
2:23
simply define a set of
2:25
animations or transition effects that
2:28
will be applied
2:31
automatically whenever we will be making
2:33
so with first will be horizontal scroll
2:36
second will be vertical
2:39
scroll then we'll be also be rotating
2:42
the
2:43
image zooming in so these are random
2:47
animation effects that will be applied
2:49
fading image so we have just defined it
2:51
inside this array of animations then we
2:54
just need to get the image files which
2:57
are present so for this I will just
2:59
write a simple function get image files
3:02
so all my image files as you can see it
3:04
is present in the home directory so you
3:08
can just pass the directory where all
3:10
your images are present after that I
3:13
just need to define this function here
3:15
which is get image
3:17
files it will essentially go to this
3:19
directory and return all the images
3:21
which are supported extensions jpg png
3:25
bmp jpg so once you get all your image
3:28
files you can simply loop through like
3:34
this and for each image we can read this
3:37
image by the open CV method image read
3:42
after reading it we
3:45
will basically apply the
3:53
animation using the random module so we
3:55
are applying the random animation using
3:58
that animations array I is equal to zero
4:01
and we'll be applying the starting
4:03
time time dot time and inside this uh
4:08
while
4:10
loop we will just increment the value of
4:13
i by one so after each image I will
4:17
increment the value of i and then we
4:20
will apply this
4:22
animation
4:24
it image
4:27
I each frame so after this we will show
4:30
this image inside the window by this
4:33
image show method so this will be a sim
4:38
title of the window will be image
4:40
slideshow and the frame will be shown so
4:44
then we will wait for certain amount of
4:47
time here so this is set to
4:49
10 so here we are waiting for each
4:56
image and then we are navigating to the
4:59
next image so here we are binding
5:02
some shortcuts so if you press the Q
5:05
keyboard Q key on the keyboard your
5:07
application will close and then we are
5:10
showing the animation for 3 seconds and
5:12
then we are breaking to the next
5:14
image so you can see we are showing the
5:17
animation for 3 seconds and then we are
5:20
breaking
5:23
it so then we are destroying all the
5:26
windows coming out of this
5:30
loop so that's all that is needed for
5:34
this application so now we just need to
5:37
define all these five animations that we
5:39
have defined here which is horizontal
5:41
scroll vertical scroll rotate image
5:44
these are all the five functions i have
5:46
given all the source code in the
5:48
description of the video
5:55
so so these are all the five functions
5:58
which are there so I will just define
6:00
this and explain you what is happening
6:02
so we are just applying the OpenCV
6:05
animations all these animations and
6:08
effects are supported by Open CV so you
6:10
can see zooming in rotating this image
6:13
like this vertical scroll horizontal
6:17
scroll all that
6:19
stuff
6:21
so this is essentially this if you you
6:25
will see it is saying on line number 49
6:27
image is not defined
6:31
so this will be
6:33
image files
6:41
sorry so now you can see it is appearing
6:43
it for 2 seconds and then it's
6:46
navigating to the next image with all
6:48
these cool little transition and
6:51
animating effects right
6:53
here it is also rotating fading zooming
6:57
in on a particular image so you can do
7:00
this very easily inside OpenCV and numpy
7:03
so all the source code is given in the
7:04
description of the video uh thank you
7:07
very much for watching this video and
7:09
also check out my website
7:11
freemediatools.com
7:13
uh which contains thousands of tools
#Animated Films
#Clip Art & Animated GIFs
#Movies
#Multimedia Software
#Online Goodies
#Online Media
#Online Video
#Scripting Languages