WEBVTT

00:00.480 --> 00:02.480
uh hello guys uh welcome to this video

00:02.480 --> 00:04.400
so in this video I will show you how to

00:04.400 --> 00:06.720
animate a bunch of images which is

00:06.720 --> 00:10.240
present inside a directory uh in Open CV

00:10.240 --> 00:13.480
with multiple transition effects and

00:13.480 --> 00:15.839
animations let me just launch the

00:15.839 --> 00:17.680
application right here from the terminal

00:17.680 --> 00:19.439
so you will see it's a simple Python

00:19.439 --> 00:22.119
script which will animate all these

00:22.119 --> 00:25.760
images inside a window with the multiple

00:25.760 --> 00:28.640
transition effects so let me just launch

00:28.640 --> 00:30.679
this

00:30.679 --> 00:33.200
application so now you can see that each

00:33.200 --> 00:36.079
image will appear for 3 seconds and then

00:36.079 --> 00:38.320
it will go away with uh random

00:38.320 --> 00:41.320
transition animation effects it's a

00:41.320 --> 00:43.520
slideshow you can see it will navigate

00:43.520 --> 00:44.680
to the next

00:44.680 --> 00:47.440
image so all these images which are

00:47.440 --> 00:49.120
present right here in the directory one

00:49.120 --> 00:52.160
by one each image will appear and as you

00:52.160 --> 00:54.719
can see you can build out this nice

00:54.719 --> 00:55.800
little

00:55.800 --> 00:59.120
slideshow inside the open CV so then

00:59.120 --> 01:00.840
automatically it will

01:00.840 --> 01:03.520
close so all the script I have given in

01:03.520 --> 01:05.280
the description of the video so for

01:05.280 --> 01:08.320
building this you need quite a uh lot of

01:08.320 --> 01:10.400
packages so first of all you just need

01:10.400 --> 01:14.560
to install Open CV

01:14.560 --> 01:18.320
so Open CV- Python this is the first

01:18.320 --> 01:20.680
module that you need to

01:20.680 --> 01:24.720
install secondly you also need the NumPy

01:24.720 --> 01:26.600
module as

01:26.600 --> 01:29.680
well so also install this as well i've

01:29.680 --> 01:32.320
already installed both these modules so

01:32.320 --> 01:35.200
now I will show you from scratch how to

01:35.200 --> 01:38.000
build this

01:38.360 --> 01:41.280
so all the source code will be given in

01:41.280 --> 01:43.560
the description of the video so first of

01:43.560 --> 01:46.079
all just you need to require the

01:46.079 --> 01:50.079
necessary packages so we will require

01:50.079 --> 01:56.799
the open CV package and numpy 2 numpy

01:56.799 --> 01:59.759
package as well then we need the

01:59.759 --> 02:02.159
operating system module the time module

02:02.159 --> 02:04.600
and the random module as

02:04.600 --> 02:08.319
well so these are built-in modules

02:08.319 --> 02:10.520
and after that we need

02:10.520 --> 02:12.200
to

02:12.200 --> 02:13.959
actually

02:13.959 --> 02:17.920
define inside the main

02:19.160 --> 02:23.160
function so right here we will

02:23.160 --> 02:25.959
simply define a set of

02:25.959 --> 02:28.480
animations or transition effects that

02:28.480 --> 02:31.480
will be applied

02:31.480 --> 02:33.840
automatically whenever we will be making

02:33.840 --> 02:36.879
so with first will be horizontal scroll

02:36.879 --> 02:39.239
second will be vertical

02:39.239 --> 02:42.319
scroll then we'll be also be rotating

02:42.319 --> 02:43.560
the

02:43.560 --> 02:47.040
image zooming in so these are random

02:47.040 --> 02:49.760
animation effects that will be applied

02:49.760 --> 02:51.920
fading image so we have just defined it

02:51.920 --> 02:54.959
inside this array of animations then we

02:54.959 --> 02:57.360
just need to get the image files which

02:57.360 --> 02:59.599
are present so for this I will just

02:59.599 --> 03:02.319
write a simple function get image files

03:02.319 --> 03:04.319
so all my image files as you can see it

03:04.319 --> 03:08.080
is present in the home directory so you

03:08.080 --> 03:10.159
can just pass the directory where all

03:10.159 --> 03:13.200
your images are present after that I

03:13.200 --> 03:15.040
just need to define this function here

03:15.040 --> 03:17.480
which is get image

03:17.480 --> 03:19.920
files it will essentially go to this

03:19.920 --> 03:21.920
directory and return all the images

03:21.920 --> 03:25.280
which are supported extensions jpg png

03:25.280 --> 03:28.879
bmp jpg so once you get all your image

03:28.879 --> 03:34.760
files you can simply loop through like

03:34.760 --> 03:37.760
this and for each image we can read this

03:37.760 --> 03:42.159
image by the open CV method image read

03:42.159 --> 03:45.159
after reading it we

03:45.159 --> 03:49.200
will basically apply the

03:53.080 --> 03:55.920
animation using the random module so we

03:55.920 --> 03:58.239
are applying the random animation using

03:58.239 --> 04:01.360
that animations array I is equal to zero

04:01.360 --> 04:03.799
and we'll be applying the starting

04:03.799 --> 04:08.799
time time dot time and inside this uh

04:08.799 --> 04:10.040
while

04:10.040 --> 04:13.519
loop we will just increment the value of

04:13.519 --> 04:17.919
i by one so after each image I will

04:17.919 --> 04:20.880
increment the value of i and then we

04:20.880 --> 04:22.680
will apply this

04:22.680 --> 04:24.440
animation

04:24.440 --> 04:27.080
it image

04:27.080 --> 04:30.720
I each frame so after this we will show

04:30.720 --> 04:33.600
this image inside the window by this

04:33.600 --> 04:38.240
image show method so this will be a sim

04:38.240 --> 04:40.280
title of the window will be image

04:40.280 --> 04:44.080
slideshow and the frame will be shown so

04:44.080 --> 04:47.680
then we will wait for certain amount of

04:47.680 --> 04:49.960
time here so this is set to

04:49.960 --> 04:56.440
10 so here we are waiting for each

04:56.440 --> 04:59.440
image and then we are navigating to the

04:59.440 --> 05:02.120
next image so here we are binding

05:02.120 --> 05:05.040
some shortcuts so if you press the Q

05:05.040 --> 05:07.520
keyboard Q key on the keyboard your

05:07.520 --> 05:10.160
application will close and then we are

05:10.160 --> 05:12.400
showing the animation for 3 seconds and

05:12.400 --> 05:14.440
then we are breaking to the next

05:14.440 --> 05:17.280
image so you can see we are showing the

05:17.280 --> 05:20.240
animation for 3 seconds and then we are

05:20.240 --> 05:22.560
breaking

05:23.639 --> 05:26.479
it so then we are destroying all the

05:26.479 --> 05:30.120
windows coming out of this

05:30.120 --> 05:34.240
loop so that's all that is needed for

05:34.240 --> 05:37.120
this application so now we just need to

05:37.120 --> 05:39.680
define all these five animations that we

05:39.680 --> 05:41.520
have defined here which is horizontal

05:41.520 --> 05:44.880
scroll vertical scroll rotate image

05:44.880 --> 05:46.880
these are all the five functions i have

05:46.880 --> 05:48.400
given all the source code in the

05:48.400 --> 05:51.600
description of the video

05:55.880 --> 05:58.880
so so these are all the five functions

05:58.880 --> 06:00.639
which are there so I will just define

06:00.639 --> 06:02.880
this and explain you what is happening

06:02.880 --> 06:05.880
so we are just applying the OpenCV

06:05.880 --> 06:08.080
animations all these animations and

06:08.080 --> 06:10.240
effects are supported by Open CV so you

06:10.240 --> 06:13.759
can see zooming in rotating this image

06:13.759 --> 06:17.120
like this vertical scroll horizontal

06:17.120 --> 06:19.560
scroll all that

06:19.560 --> 06:21.560
stuff

06:21.560 --> 06:25.039
so this is essentially this if you you

06:25.039 --> 06:27.440
will see it is saying on line number 49

06:27.440 --> 06:31.199
image is not defined

06:31.199 --> 06:33.880
so this will be

06:33.880 --> 06:37.520
image files

06:41.240 --> 06:43.919
sorry so now you can see it is appearing

06:43.919 --> 06:46.800
it for 2 seconds and then it's

06:46.800 --> 06:48.880
navigating to the next image with all

06:48.880 --> 06:51.080
these cool little transition and

06:51.080 --> 06:53.639
animating effects right

06:53.639 --> 06:57.120
here it is also rotating fading zooming

06:57.120 --> 07:00.080
in on a particular image so you can do

07:00.080 --> 07:03.120
this very easily inside OpenCV and numpy

07:03.120 --> 07:04.960
so all the source code is given in the

07:04.960 --> 07:07.280
description of the video uh thank you

07:07.280 --> 07:09.440
very much for watching this video and

07:09.440 --> 07:11.280
also check out my website

07:11.280 --> 07:13.120
freemediatools.com

07:13.120 --> 07:18.280
uh which contains thousands of tools
