[00:00:00.48 --> 00:00:06.
32] build your own mouse with just
[00:00:03.12 --> 00:00:09.52] 35 lines of python this is super easy
[00:00:06.32 --> 00:00:12.24] super fun and super crazy so let's get
[00:00:09.52 --> 00:00:12.24] started
[00:00:15.36 --> 00:00:20.00] before getting into the detail please
[00:00:17.12 --> 00:00:22.72] please like this video and subscribe to
[00:00:20.00 --> 00:00:26.24] this channel otherwise grandma will
[00:00:22.72 --> 00:00:28.32] smash a watermelon on youtube
[00:00:26.24 --> 00:00:30.96] start with this project you will need a
[00:00:28.32 --> 00:00:33.20] python code editor and for our case
[00:00:30.96 --> 00:00:34.80] would be using pycharm
[00:00:33.20 --> 00:00:37.04] the first thing you need to do is to
[00:00:34.80 --> 00:00:39.12] create a project and give some fancy
[00:00:37.04 --> 00:00:41.28] name to your project so that you feel
[00:00:39.12 --> 00:00:44.16] better and here i would be giving name
[00:00:41.28 --> 00:00:46.64] virtual mouse or you can give ai mouse
[00:00:44.16 --> 00:00:48.88] and press enter this will take few
[00:00:46.64 --> 00:00:51.20] seconds for the pie charm to start the
[00:00:48.88 --> 00:00:54.00] project once this python is ready we'll
[00:00:51.20 --> 00:00:56.40] install three simple packages bang bang
[00:00:54.00 --> 00:00:59.20] bang so let's start that bang bang bang
[00:00:56.40 --> 00:01:00.24] i will go to the file and find this
[00:00:59.20 --> 00:01:02.72] settings
[00:01:00.24 --> 00:01:05.44] and then a new pop-up will come and we
[00:01:02.72 --> 00:01:08.40] will click on this project virtual mouse
[00:01:05.44 --> 00:01:11.44] click on python interpreter and hit this
[00:01:08.40 --> 00:01:14.00] plus icon to install a package
[00:01:11.44 --> 00:01:17.92] and here you can access any package but
[00:01:14.00 --> 00:01:20.40] i would be going with opencv dash python
[00:01:17.92 --> 00:01:22.80] click on this guy and then hit this
[00:01:20.40 --> 00:01:25.84] install package and this will take
[00:01:22.80 --> 00:01:28.80] literally few seconds to install opencv
[00:01:25.84 --> 00:01:32.00] python for your project
[00:01:28.80 --> 00:01:34.80] the second package is a mediapipe and
[00:01:32.00 --> 00:01:37.04] this is a very popular media pipe
[00:01:34.80 --> 00:01:40.56] developed by google so just click on
[00:01:37.04 --> 00:01:42.96] this guy and hit on install package and
[00:01:40.56 --> 00:01:45.76] the last project is very simple but
[00:01:42.96 --> 00:01:48.56] powerful pi auto
[00:01:45.76 --> 00:01:50.48] gui and click on this dude again and
[00:01:48.56 --> 00:01:53.12] then hit install
[00:01:50.48 --> 00:01:55.60] that's it your three packages install
[00:01:53.12 --> 00:01:58.24] you are done with bang bang bang and i
[00:01:55.60 --> 00:02:01.28] will click on this cross and this cross
[00:01:58.24 --> 00:02:03.68] and i'm come back to this pycharm
[00:02:01.28 --> 00:02:06.48] controller backspace you have a clean
[00:02:03.68 --> 00:02:08.80] slate and to have our awesome powerful
[00:02:06.48 --> 00:02:12.08] mouse we will just need to code five
[00:02:08.80 --> 00:02:14.64] simple steps 35 lines and the first step
[00:02:12.08 --> 00:02:17.84] is to open up the video camera with just
[00:02:14.64 --> 00:02:20.24] six lines of code so let's get started
[00:02:17.84 --> 00:02:23.12] by importing opencv and we'll be
[00:02:20.24 --> 00:02:26.00] importing cb2 and first thing is to
[00:02:23.12 --> 00:02:27.92] capture the video from your video source
[00:02:26.00 --> 00:02:31.52] and for that purpose i will have a
[00:02:27.92 --> 00:02:35.28] variable called cap and i will go to cv2
[00:02:31.52 --> 00:02:37.92] and ask cb2 to capture video so this
[00:02:35.28 --> 00:02:40.72] would be video capture and i will put
[00:02:37.92 --> 00:02:42.64] zero that means the first video source i
[00:02:40.72 --> 00:02:44.80] need to capture
[00:02:42.64 --> 00:02:46.72] then i want to this video to be run
[00:02:44.80 --> 00:02:49.44] continuously that means i'll be running
[00:02:46.72 --> 00:02:52.64] a while loop and for that purpose i will
[00:02:49.44 --> 00:02:55.60] write y and since this loop is running
[00:02:52.64 --> 00:02:58.00] forever i would just put true that means
[00:02:55.60 --> 00:02:59.92] it'd be running forever inside this
[00:02:58.00 --> 00:03:03.28] first thing is to
[00:02:59.92 --> 00:03:05.36] capture the frame of the video and that
[00:03:03.28 --> 00:03:08.00] purpose the first variable i don't need
[00:03:05.36 --> 00:03:08.72] it and second one would be frame equals
[00:03:08.00 --> 00:03:11.12] to
[00:03:08.72 --> 00:03:12.40] from the capture i want to read whatever
[00:03:11.12 --> 00:03:15.28] is captured
[00:03:12.40 --> 00:03:18.72] and the next thing is just to show the
[00:03:15.28 --> 00:03:21.20] image i will go back to cb2 and hey cb2
[00:03:18.72 --> 00:03:24.32] i need to show some image that means i
[00:03:21.20 --> 00:03:26.64] am for image and show is to just display
[00:03:24.32 --> 00:03:30.16] the image and you will pass two things
[00:03:26.64 --> 00:03:33.20] the name of the frame and this would be
[00:03:30.16 --> 00:03:34.40] virtual mouse or some fancy name you
[00:03:33.20 --> 00:03:37.68] want to give
[00:03:34.40 --> 00:03:40.56] and pass the frame and the last line is
[00:03:37.68 --> 00:03:41.92] cv2 and then weight key
[00:03:40.56 --> 00:03:44.16] just press
[00:03:41.92 --> 00:03:46.48] one that's it you have written six lines
[00:03:44.16 --> 00:03:48.64] of code and if that is working
[00:03:46.48 --> 00:03:50.72] if you click on this guy a video will
[00:03:48.64 --> 00:03:52.72] pop up so are you ready to test this
[00:03:50.72 --> 00:03:54.72] part i'm very excited and nervous
[00:03:52.72 --> 00:03:57.68] whether this is working or not so i'm
[00:03:54.72 --> 00:03:59.60] hitting on this dude and let's see wow
[00:03:57.68 --> 00:04:02.80] you see here i am here i am here i am
[00:03:59.60 --> 00:04:05.60] here i am so with just six simple lines
[00:04:02.80 --> 00:04:07.76] of code you would be able to pop up a
[00:04:05.60 --> 00:04:09.12] video on your screen
[00:04:07.76 --> 00:04:11.60] isn't it fun
[00:04:09.12 --> 00:04:15.04] and we are officially done with our step
[00:04:11.60 --> 00:04:18.00] number one and four more steps to go and
[00:04:15.04 --> 00:04:20.80] our second step is to detect the hand
[00:04:18.00 --> 00:04:23.28] and to detect the hand we will need to
[00:04:20.80 --> 00:04:26.40] import media pipe so i am going to the
[00:04:23.28 --> 00:04:29.68] media pipe and giving a small name just
[00:04:26.40 --> 00:04:31.84] mp and from this media pipe they have a
[00:04:29.68 --> 00:04:35.36] lot of solutions but all i need to is
[00:04:31.84 --> 00:04:39.44] the hand detector so hand detector is
[00:04:35.36 --> 00:04:42.64] equals to mp dot solutions and they have
[00:04:39.44 --> 00:04:46.00] hand solutions i i want to call the hand
[00:04:42.64 --> 00:04:48.72] method so we have some hand detector and
[00:04:46.00 --> 00:04:51.92] detecting anything from frame or video
[00:04:48.72 --> 00:04:54.80] the rgb mode is the best one or you can
[00:04:51.92 --> 00:04:58.00] use grayscale too so i can give a
[00:04:54.80 --> 00:05:01.68] variable name rzb frame and this is
[00:04:58.00 --> 00:05:03.76] nothing but cv2 will convert the color
[00:05:01.68 --> 00:05:07.76] and it will convert the color of the
[00:05:03.76 --> 00:05:12.80] frame by using cb2 and then
[00:05:07.76 --> 00:05:15.68] bzr to r z b and it will be converted
[00:05:12.80 --> 00:05:16.88] and after that you just need just two
[00:05:15.68 --> 00:05:19.04] lines of code
[00:05:16.88 --> 00:05:22.32] first thing is using the hand detector
[00:05:19.04 --> 00:05:24.24] you would be processing the rgb frame
[00:05:22.32 --> 00:05:26.08] and to process this you will get some
[00:05:24.24 --> 00:05:28.80] output from the process so i am
[00:05:26.08 --> 00:05:30.48] declaring a variable name output and on
[00:05:28.80 --> 00:05:31.92] the right side i would be calling the
[00:05:30.48 --> 00:05:32.80] hand detector
[00:05:31.92 --> 00:05:33.84] to
[00:05:32.80 --> 00:05:36.00] process
[00:05:33.84 --> 00:05:38.40] and the parameter i will be passing this
[00:05:36.00 --> 00:05:41.60] rzb frame that's it
[00:05:38.40 --> 00:05:44.24] so once i pass this rgb frame i should
[00:05:41.60 --> 00:05:45.28] be getting some hands and that hand
[00:05:44.24 --> 00:05:47.60] should be
[00:05:45.28 --> 00:05:48.72] output dot multi
[00:05:47.60 --> 00:05:51.12] and
[00:05:48.72 --> 00:05:53.28] landmarks so we will talk about the
[00:05:51.12 --> 00:05:56.16] length marks in a second but
[00:05:53.28 --> 00:05:59.04] once you run this guy let's uh print out
[00:05:56.16 --> 00:06:01.52] the hands and you might face some error
[00:05:59.04 --> 00:06:03.76] don't worry we will solve it so i'm
[00:06:01.52 --> 00:06:05.76] hitting on this guy and let's see
[00:06:03.76 --> 00:06:07.84] whether i'm getting some error but
[00:06:05.76 --> 00:06:11.12] pycharm will give you what you need to
[00:06:07.84 --> 00:06:14.80] do it will say downgrade the protobuf
[00:06:11.12 --> 00:06:17.68] package to 3.20 point something version
[00:06:14.80 --> 00:06:20.40] and we know how to install a package we
[00:06:17.68 --> 00:06:22.96] need to go to do some bang bang bang
[00:06:20.40 --> 00:06:25.76] and that bang bang bang is file
[00:06:22.96 --> 00:06:29.04] and then settings and then just click on
[00:06:25.76 --> 00:06:31.28] this guy and we need proto buff
[00:06:29.04 --> 00:06:34.24] but here we will need to specify a
[00:06:31.28 --> 00:06:36.64] version if you get this error click on
[00:06:34.24 --> 00:06:39.12] this guy you will see three point twenty
[00:06:36.64 --> 00:06:42.08] point three point twenty point zero and
[00:06:39.12 --> 00:06:44.40] then hit this install package
[00:06:42.08 --> 00:06:46.80] this will take literally few seconds to
[00:06:44.40 --> 00:06:49.36] bang bang bang and once this is done
[00:06:46.80 --> 00:06:52.16] just cross this guy cross this guy come
[00:06:49.36 --> 00:06:54.88] back and click on this dude and if you
[00:06:52.16 --> 00:06:57.88] are lucky there would not be any error
[00:06:54.88 --> 00:07:03.28] and cb2 has not
[00:06:57.88 --> 00:07:05.92] bcr2cv2 dot color underscore bgr to rgb
[00:07:03.28 --> 00:07:08.32] and click on this guy so hopefully there
[00:07:05.92 --> 00:07:11.76] is no error you see you see none none
[00:07:08.32 --> 00:07:13.36] but if i raise my hand you see something
[00:07:11.76 --> 00:07:16.24] different there
[00:07:13.36 --> 00:07:18.88] we'll know what it is but at least i see
[00:07:16.24 --> 00:07:21.04] something if i raise my hand over there
[00:07:18.88 --> 00:07:24.48] if i move this guy you will see
[00:07:21.04 --> 00:07:26.64] if i raise my hand you see some z axis
[00:07:24.48 --> 00:07:29.36] and landmark there so this is the fun
[00:07:26.64 --> 00:07:31.68] part my dear friend and i would like to
[00:07:29.36 --> 00:07:35.12] show the hand to you and then we'll be
[00:07:31.68 --> 00:07:36.64] done with this step and to do so you can
[00:07:35.12 --> 00:07:39.60] right here if
[00:07:36.64 --> 00:07:41.52] hands is there and for every hand you
[00:07:39.60 --> 00:07:45.36] will get the hand so
[00:07:41.52 --> 00:07:47.84] for hand in hands that means every hands
[00:07:45.36 --> 00:07:50.64] actually this is hand landmark and
[00:07:47.84 --> 00:07:52.80] landmark is nothing but some point on
[00:07:50.64 --> 00:07:54.72] your hand so this is a landmark this is
[00:07:52.80 --> 00:07:58.32] a landmark this is a landmark and you
[00:07:54.72 --> 00:07:59.76] have 21 landmarks on a hand we will see
[00:07:58.32 --> 00:08:02.16] it in a second
[00:07:59.76 --> 00:08:04.64] so we have if you have hands
[00:08:02.16 --> 00:08:07.28] that means actually every landmark and
[00:08:04.64 --> 00:08:10.16] you will go through every hands and for
[00:08:07.28 --> 00:08:11.76] each hands you want to draw those
[00:08:10.16 --> 00:08:12.64] and for drawing
[00:08:11.76 --> 00:08:14.96] this
[00:08:12.64 --> 00:08:17.68] media pipe gives you some drawing you
[00:08:14.96 --> 00:08:21.84] tell so you can declare a variable here
[00:08:17.68 --> 00:08:24.72] drawing utils equals to mp dot solutions
[00:08:21.84 --> 00:08:27.60] dot drawing your tails and here you will
[00:08:24.72 --> 00:08:30.64] say like hey drawing your tails
[00:08:27.60 --> 00:08:33.20] all you need to do is to draw landmarks
[00:08:30.64 --> 00:08:34.72] and you will pass the hand and where
[00:08:33.20 --> 00:08:36.72] it's need to be
[00:08:34.72 --> 00:08:39.36] drawing it needs to be drawn on the
[00:08:36.72 --> 00:08:42.32] frame so that you can see the hand
[00:08:39.36 --> 00:08:45.04] landmarks on the frame that's it so you
[00:08:42.32 --> 00:08:48.00] are calling drawing details to draw
[00:08:45.04 --> 00:08:50.56] landmark that means every point of your
[00:08:48.00 --> 00:08:52.72] finger and it would be displayed on the
[00:08:50.56 --> 00:08:56.00] frame and if you have done this
[00:08:52.72 --> 00:08:59.20] correctly and you can raise your hand or
[00:08:56.00 --> 00:09:02.32] you need to run this dude and then once
[00:08:59.20 --> 00:09:05.36] this is starting you can raise your hand
[00:09:02.32 --> 00:09:08.48] and you see i'm raising my hand and
[00:09:05.36 --> 00:09:12.00] every point in my hand is there so there
[00:09:08.48 --> 00:09:14.64] are total 21 starting point zero one two
[00:09:12.00 --> 00:09:16.88] and all these points here you can see so
[00:09:14.64 --> 00:09:20.16] we are officially done with the step
[00:09:16.88 --> 00:09:23.20] number two you see how easy to code some
[00:09:20.16 --> 00:09:25.36] fun thing in python i'm very excited i
[00:09:23.20 --> 00:09:27.76] will see you in the step number three in
[00:09:25.36 --> 00:09:31.36] the step number three all we need to do
[00:09:27.76 --> 00:09:34.00] is to separate our index finger t so
[00:09:31.36 --> 00:09:37.28] that we can use this in the future to
[00:09:34.00 --> 00:09:39.60] move the cursor or the mouse pointer and
[00:09:37.28 --> 00:09:42.88] to have this fun we need to know what
[00:09:39.60 --> 00:09:48.00] are the different landmarks in our hand
[00:09:42.88 --> 00:09:51.36] and it starts with 0 and 0 1 2 3 4 5 6 7
[00:09:48.00 --> 00:09:53.84] 8 and you can search google that what
[00:09:51.36 --> 00:09:56.16] are different landmarks on your hand
[00:09:53.84 --> 00:09:58.24] but to get the landmarks all you need to
[00:09:56.16 --> 00:10:02.56] do here declare a variable called
[00:09:58.24 --> 00:10:05.04] landmarks equals to hand dot landmark
[00:10:02.56 --> 00:10:07.52] and once you get this landmark since you
[00:10:05.04 --> 00:10:10.00] have like so many different landmark
[00:10:07.52 --> 00:10:12.56] point they starts with zero you need to
[00:10:10.00 --> 00:10:16.40] iterate over the landmarks and get the
[00:10:12.56 --> 00:10:18.48] id or the index of every landmark and
[00:10:16.40 --> 00:10:21.84] that's why we need to convert these
[00:10:18.48 --> 00:10:27.12] landmarks to an enumerate and for that
[00:10:21.84 --> 00:10:30.32] purpose i will do for id and landmark
[00:10:27.12 --> 00:10:33.28] in enumerate and we will pass the
[00:10:30.32 --> 00:10:36.08] landmarks that means we'll pass all the
[00:10:33.28 --> 00:10:37.44] landmarks and we will get count zero one
[00:10:36.08 --> 00:10:39.44] two three four
[00:10:37.44 --> 00:10:43.92] and inside it the first thing we will
[00:10:39.44 --> 00:10:45.92] need to do if the id is equals to eight
[00:10:43.92 --> 00:10:51.28] the reason we are saying 8 because this
[00:10:45.92 --> 00:10:53.36] started with 0 1 2 3 4 5 6 7 8 this is
[00:10:51.28 --> 00:10:57.04] the tip is number 8.
[00:10:53.36 --> 00:10:59.60] and inside if we check if id equals to 8
[00:10:57.04 --> 00:11:00.96] and inside it we will do some work that
[00:10:59.60 --> 00:11:03.36] means we maybe
[00:11:00.96 --> 00:11:05.76] cover a circle over there to cover a
[00:11:03.36 --> 00:11:09.36] circle we need to do few stuff we need
[00:11:05.76 --> 00:11:10.16] to know what is the x and y position of
[00:11:09.36 --> 00:11:12.64] this
[00:11:10.16 --> 00:11:14.56] finger point and to do so we will come
[00:11:12.64 --> 00:11:18.80] back to this line but before that we
[00:11:14.56 --> 00:11:22.40] will get x is equals to landmark dot x
[00:11:18.80 --> 00:11:25.20] and y equals to landmark
[00:11:22.40 --> 00:11:25.20] dot y
[00:11:25.44 --> 00:11:30.72] so once we get the x and y position just
[00:11:28.08 --> 00:11:33.04] print x and y and we'll see this is not
[00:11:30.72 --> 00:11:36.64] an integer number so we'll click on
[00:11:33.04 --> 00:11:39.04] these two and here we will see uh since
[00:11:36.64 --> 00:11:41.92] we have this one here if we have this
[00:11:39.04 --> 00:11:43.44] will see some fraction number over here
[00:11:41.92 --> 00:11:45.84] but we need some
[00:11:43.44 --> 00:11:48.80] pixel points so that we can draw some
[00:11:45.84 --> 00:11:51.52] circle over there and to do so what we
[00:11:48.80 --> 00:11:54.88] can do is whatever this
[00:11:51.52 --> 00:11:57.04] landmark x is a fraction of the whole
[00:11:54.88 --> 00:11:59.92] length and you will know that if my
[00:11:57.04 --> 00:12:02.40] finger is on the left side this is okay
[00:11:59.92 --> 00:12:05.12] if i move my hand in my screen on the
[00:12:02.40 --> 00:12:07.68] other side it here it goes different
[00:12:05.12 --> 00:12:10.48] direction that means if you see the
[00:12:07.68 --> 00:12:13.12] video it's actually mirror of what you
[00:12:10.48 --> 00:12:14.32] are doing but don't worry we can easily
[00:12:13.12 --> 00:12:16.88] fix it
[00:12:14.32 --> 00:12:19.52] and the fixing is here we will say like
[00:12:16.88 --> 00:12:23.52] hey the value of frame would be nothing
[00:12:19.52 --> 00:12:25.36] but cv2 will flip it and it will flip
[00:12:23.52 --> 00:12:28.16] the frame and
[00:12:25.36 --> 00:12:31.52] y axis because 0 means flip on the x
[00:12:28.16 --> 00:12:33.60] axis 1 means flip on the y axis and if
[00:12:31.52 --> 00:12:34.40] you do so you will see
[00:12:33.60 --> 00:12:37.44] that
[00:12:34.40 --> 00:12:39.60] on the screen you see and on my face
[00:12:37.44 --> 00:12:41.60] it's going on the right side and if i go
[00:12:39.60 --> 00:12:43.52] to the right side you see this below
[00:12:41.60 --> 00:12:46.48] here is getting close to
[00:12:43.52 --> 00:12:49.52] 1 and if it goes to this side close to
[00:12:46.48 --> 00:12:52.80] the left side it goes close to 0 that
[00:12:49.52 --> 00:12:56.40] means the whole axis needs to be
[00:12:52.80 --> 00:12:58.88] multiplied by the width of the frame
[00:12:56.40 --> 00:13:02.24] and we can easily get the width of the
[00:12:58.88 --> 00:13:05.28] frame by using cb2 it's very simple so
[00:13:02.24 --> 00:13:08.40] all we need to do here we can have say
[00:13:05.28 --> 00:13:10.32] frame uh the first one is height and the
[00:13:08.40 --> 00:13:12.56] second one is the frame
[00:13:10.32 --> 00:13:14.32] width and we have another thing if you
[00:13:12.56 --> 00:13:18.00] want to use it or not use it just
[00:13:14.32 --> 00:13:18.80] underscore and this would be frame dot
[00:13:18.00 --> 00:13:20.96] shape
[00:13:18.80 --> 00:13:23.52] and from the shape of the frame we can
[00:13:20.96 --> 00:13:26.96] get the frame height and frame width
[00:13:23.52 --> 00:13:28.96] and here we can say like hey landmark x
[00:13:26.96 --> 00:13:33.12] multiplied by frame
[00:13:28.96 --> 00:13:35.20] width because x axis is horizontal axis
[00:13:33.12 --> 00:13:38.40] similarly y would be
[00:13:35.20 --> 00:13:42.08] multiplied by frame height because y
[00:13:38.40 --> 00:13:44.48] axis is the vertical axis and if we run
[00:13:42.08 --> 00:13:47.60] this guy you will see the for the
[00:13:44.48 --> 00:13:50.80] landmark now we will get a big number
[00:13:47.60 --> 00:13:53.20] not like between 0 to 1 but this is not
[00:13:50.80 --> 00:13:54.96] an integer we can easily convert this
[00:13:53.20 --> 00:13:57.68] guy inside an
[00:13:54.96 --> 00:14:01.36] integer so we can just write integer or
[00:13:57.68 --> 00:14:02.40] here integer and we can wrap it around
[00:14:01.36 --> 00:14:06.08] integer
[00:14:02.40 --> 00:14:08.64] and now if we run this guy you will see
[00:14:06.08 --> 00:14:11.56] some kind of number you see like some
[00:14:08.64 --> 00:14:16.00] kind of number you see like a 400
[00:14:11.56 --> 00:14:16.88] 278 something like this on the output
[00:14:16.00 --> 00:14:19.12] and
[00:14:16.88 --> 00:14:21.92] once we have this we want to draw it
[00:14:19.12 --> 00:14:24.88] only for the index finger and we know
[00:14:21.92 --> 00:14:27.84] the uh position of the index finger tip
[00:14:24.88 --> 00:14:32.64] is 8 and to do so
[00:14:27.84 --> 00:14:35.76] we can check like if id is equals to 8
[00:14:32.64 --> 00:14:38.00] in that case we can tell cv2 you need to
[00:14:35.76 --> 00:14:40.16] draw some circuit and you need to
[00:14:38.00 --> 00:14:42.32] provide some parameter first where it
[00:14:40.16 --> 00:14:44.88] need to be displayed this would be on
[00:14:42.32 --> 00:14:48.24] the frame and the second thing is to
[00:14:44.88 --> 00:14:50.48] provide the center of the circuit and
[00:14:48.24 --> 00:14:52.80] center would be x and y
[00:14:50.48 --> 00:14:56.08] third parameter you need to pass is the
[00:14:52.80 --> 00:14:58.08] radius of the circle this could be 10
[00:14:56.08 --> 00:15:01.04] pixel and the last thing would be the
[00:14:58.08 --> 00:15:05.92] color and if we want to make it a yellow
[00:15:01.04 --> 00:15:08.24] color this would be 0 to 55 and then 255
[00:15:05.92 --> 00:15:10.80] and if you have done this correctly my
[00:15:08.24 --> 00:15:13.20] dear friend you can click on this guy
[00:15:10.80 --> 00:15:16.80] and you will see once you raise your
[00:15:13.20 --> 00:15:19.92] finger you see there is a yellow circuit
[00:15:16.80 --> 00:15:21.84] on the index finger only none other
[00:15:19.92 --> 00:15:25.52] landmark has a yellow
[00:15:21.84 --> 00:15:28.24] only only only this finger or the index
[00:15:25.52 --> 00:15:29.76] finger of all the hands you have will
[00:15:28.24 --> 00:15:32.96] have it if you have like 20 different
[00:15:29.76 --> 00:15:36.08] hands every index finger will have this
[00:15:32.96 --> 00:15:38.32] yellow mark so we have successfully
[00:15:36.08 --> 00:15:41.68] finished our step number three to
[00:15:38.32 --> 00:15:45.04] identify our index finger the next task
[00:15:41.68 --> 00:15:48.08] is to move the mouse by using the index
[00:15:45.04 --> 00:15:49.92] finger step number four
[00:15:48.08 --> 00:15:52.80] step number four we can see this yellow
[00:15:49.92 --> 00:15:56.08] circle in the step number four our goal
[00:15:52.80 --> 00:15:59.28] is to move the mouse pointer by using
[00:15:56.08 --> 00:16:01.60] our finger and to do so we have this
[00:15:59.28 --> 00:16:04.48] very simple very powerful package
[00:16:01.60 --> 00:16:07.44] install and that is nothing but our the
[00:16:04.48 --> 00:16:10.40] last package is pi auto gui
[00:16:07.44 --> 00:16:13.44] and by using pi auto gui once you have
[00:16:10.40 --> 00:16:15.84] this x and y position here you can
[00:16:13.44 --> 00:16:19.20] easily easily move
[00:16:15.84 --> 00:16:20.80] pi auto gui move the cursor point to the
[00:16:19.20 --> 00:16:23.20] point you want
[00:16:20.80 --> 00:16:24.24] and if you do this it will do most of
[00:16:23.20 --> 00:16:26.56] the work
[00:16:24.24 --> 00:16:29.12] but a little bit correction has to be
[00:16:26.56 --> 00:16:31.84] done but let's try this one at least
[00:16:29.12 --> 00:16:34.48] mouse is moving or not so i'm clicking
[00:16:31.84 --> 00:16:37.68] on this guy and you will see this is
[00:16:34.48 --> 00:16:40.48] popping up if i take this and you see my
[00:16:37.68 --> 00:16:43.52] cursor you see my cursor is moving and
[00:16:40.48 --> 00:16:46.88] the cursor is is moving there but it's
[00:16:43.52 --> 00:16:49.28] not actually moving the whole screen if
[00:16:46.88 --> 00:16:50.64] i move the cursor here let's say it is
[00:16:49.28 --> 00:16:53.36] just on
[00:16:50.64 --> 00:16:56.40] top of my nose very ideal location now
[00:16:53.36 --> 00:16:58.80] if i do this it goes there it goes there
[00:16:56.40 --> 00:17:01.12] it's not actually where my finger is
[00:16:58.80 --> 00:17:04.16] rather it's moving around
[00:17:01.12 --> 00:17:06.80] the reason it's doing this is because
[00:17:04.16 --> 00:17:10.32] what we are doing say if we put this
[00:17:06.80 --> 00:17:13.12] right here what it will do it will move
[00:17:10.32 --> 00:17:15.36] very close to my hand but if i take my
[00:17:13.12 --> 00:17:19.12] hand all the way to the right side it is
[00:17:15.36 --> 00:17:22.40] not going outside of this frame because
[00:17:19.12 --> 00:17:24.48] the space we are moving the mouse is
[00:17:22.40 --> 00:17:26.56] inside the frame weight
[00:17:24.48 --> 00:17:28.16] and this frame could be different size
[00:17:26.56 --> 00:17:31.04] smaller bigger
[00:17:28.16 --> 00:17:33.60] what we need to do is to scale out our
[00:17:31.04 --> 00:17:34.96] frame because your screen your display
[00:17:33.60 --> 00:17:37.76] could be bigger
[00:17:34.96 --> 00:17:39.12] than the frame for example i have here
[00:17:37.76 --> 00:17:40.80] two things
[00:17:39.12 --> 00:17:43.28] let's say this is the frame and this is
[00:17:40.80 --> 00:17:45.92] your monitor screen that means if
[00:17:43.28 --> 00:17:48.32] something is like a four pixel from here
[00:17:45.92 --> 00:17:51.36] and if this is double width then it
[00:17:48.32 --> 00:17:53.84] would be eight on this big screen if it
[00:17:51.36 --> 00:17:55.60] is seven this would be double fourteen
[00:17:53.84 --> 00:17:58.32] and it could be three times four times
[00:17:55.60 --> 00:18:00.80] bigger let's say like this guy all you
[00:17:58.32 --> 00:18:03.84] need to do is to just multiply the
[00:18:00.80 --> 00:18:06.56] factor the width of this guy
[00:18:03.84 --> 00:18:09.44] purses this guy and multiply the factor
[00:18:06.56 --> 00:18:12.56] some simple math and first thing we will
[00:18:09.44 --> 00:18:15.12] need to know to get the screen size and
[00:18:12.56 --> 00:18:17.44] this is super easy we can easily get by
[00:18:15.12 --> 00:18:20.64] using our powerful friend
[00:18:17.44 --> 00:18:23.84] by autogry and all we need to do is to
[00:18:20.64 --> 00:18:26.56] get the screen and then width
[00:18:23.84 --> 00:18:27.44] and then screen we want to get the
[00:18:26.56 --> 00:18:31.20] height
[00:18:27.44 --> 00:18:33.52] equals to pi auto gui dot size
[00:18:31.20 --> 00:18:35.76] and that's how we will get the overall
[00:18:33.52 --> 00:18:38.96] screen width and height
[00:18:35.76 --> 00:18:42.40] and after that we will need to get this
[00:18:38.96 --> 00:18:44.96] index position x position on the screen
[00:18:42.40 --> 00:18:48.40] so we can declare a variable just before
[00:18:44.96 --> 00:18:51.20] this and that would be our index
[00:18:48.40 --> 00:18:52.72] index exposition this simple method
[00:18:51.20 --> 00:18:57.44] might trick you a little bit but don't
[00:18:52.72 --> 00:19:00.08] worry this is screen width divided by
[00:18:57.44 --> 00:19:02.08] frame width that means this is your
[00:19:00.08 --> 00:19:04.00] screen and this is the frame the video
[00:19:02.08 --> 00:19:06.80] you want you are seeing right now it
[00:19:04.00 --> 00:19:08.24] means how much bigger this screen on
[00:19:06.80 --> 00:19:10.64] comparing to
[00:19:08.24 --> 00:19:13.84] the frame you have and then you just
[00:19:10.64 --> 00:19:16.40] need to multiply it by ah this x value
[00:19:13.84 --> 00:19:19.12] you have that's pretty much it and then
[00:19:16.40 --> 00:19:20.32] the similar way you can get the index
[00:19:19.12 --> 00:19:23.36] finger
[00:19:20.32 --> 00:19:26.64] y position and that is nothing but
[00:19:23.36 --> 00:19:29.44] a screen height because y is vertical
[00:19:26.64 --> 00:19:32.72] divided by frame height
[00:19:29.44 --> 00:19:35.12] multiplied by y and here to move the
[00:19:32.72 --> 00:19:38.96] mouse instead of x you will use the
[00:19:35.12 --> 00:19:41.52] index finger x and index finger y that's
[00:19:38.96 --> 00:19:43.68] it pretty much now you can click on this
[00:19:41.52 --> 00:19:46.24] guy and let's see whether this is
[00:19:43.68 --> 00:19:49.12] working so my finger is here and you see
[00:19:46.24 --> 00:19:51.52] the cursor is going this if i take one i
[00:19:49.12 --> 00:19:54.32] can take the cursor very close to this
[00:19:51.52 --> 00:19:57.92] stop button still i cannot click it but
[00:19:54.32 --> 00:20:00.32] at least at least it can go there here
[00:19:57.92 --> 00:20:03.92] or even it can come right here on the
[00:20:00.32 --> 00:20:06.88] frame so i can move the cursor based on
[00:20:03.92 --> 00:20:09.28] my finger on the frame this is very
[00:20:06.88 --> 00:20:11.76] simple but very powerful and you might
[00:20:09.28 --> 00:20:14.40] need to think little bit about the
[00:20:11.76 --> 00:20:16.88] simple math we have done here so we are
[00:20:14.40 --> 00:20:19.68] officially done with step number four
[00:20:16.88 --> 00:20:22.80] and i am very excited for the last click
[00:20:19.68 --> 00:20:25.36] option and this step number five is very
[00:20:22.80 --> 00:20:28.56] very romantic and lovely because we will
[00:20:25.36 --> 00:20:31.52] do some romantic action over here and in
[00:20:28.56 --> 00:20:34.24] this step our goal is to perform this
[00:20:31.52 --> 00:20:36.16] click operation and how we can know
[00:20:34.24 --> 00:20:38.24] there is a click have done there are
[00:20:36.16 --> 00:20:40.88] multiple ways you can do it but
[00:20:38.24 --> 00:20:45.20] what we will do is that our romantic
[00:20:40.88 --> 00:20:47.12] lovely uh dude thumb if this dude comes
[00:20:45.20 --> 00:20:49.12] to this lovely
[00:20:47.12 --> 00:20:52.00] and fancy
[00:20:49.12 --> 00:20:54.16] beauty index finger if they comes very
[00:20:52.00 --> 00:20:57.60] closer and their distance is very close
[00:20:54.16 --> 00:21:00.00] we know they are going to kiss each
[00:20:57.60 --> 00:21:03.12] other and that's how we know there is a
[00:21:00.00 --> 00:21:05.68] click event happening so don't worry we
[00:21:03.12 --> 00:21:10.64] got like id 8 because we know it starts
[00:21:05.68 --> 00:21:14.24] with 0 1 2 3 4 and this is the 8 so 4 we
[00:21:10.64 --> 00:21:16.40] can easily detect the term and we can do
[00:21:14.24 --> 00:21:18.32] like if we can just or copy these three
[00:21:16.40 --> 00:21:20.24] lines this super easy we can copy these
[00:21:18.32 --> 00:21:22.00] three lines and here
[00:21:20.24 --> 00:21:24.88] we will need to make sure we indent it
[00:21:22.00 --> 00:21:27.68] properly and here we will say this is 4
[00:21:24.88 --> 00:21:29.92] and if it is 4 this is for our
[00:21:27.68 --> 00:21:32.64] index and this is for our thumb we will
[00:21:29.92 --> 00:21:35.52] draw the thumb circle and then we will
[00:21:32.64 --> 00:21:38.16] detect index x and y please note that i
[00:21:35.52 --> 00:21:40.00] didn't copy this pi or to gui move
[00:21:38.16 --> 00:21:43.04] because we would be moving only for the
[00:21:40.00 --> 00:21:45.36] index let's see whether up to this point
[00:21:43.04 --> 00:21:46.56] is working for us or not
[00:21:45.36 --> 00:21:49.44] so if i
[00:21:46.56 --> 00:21:52.08] run this guy and if you see there are
[00:21:49.44 --> 00:21:54.64] two circles this is our dude thumb and
[00:21:52.08 --> 00:21:57.92] our index has like two different color
[00:21:54.64 --> 00:22:00.80] and our goal is to if they come closer
[00:21:57.92 --> 00:22:04.00] then we will do some click operation and
[00:22:00.80 --> 00:22:07.12] to detect these two are coming closer
[00:22:04.00 --> 00:22:10.88] together we will need to differentiate
[00:22:07.12 --> 00:22:12.88] so this would be our uh thumb exposition
[00:22:10.88 --> 00:22:16.40] this would be our thumb x position and
[00:22:12.88 --> 00:22:17.20] this would be our thumb y position
[00:22:16.40 --> 00:22:19.12] and
[00:22:17.20 --> 00:22:22.08] to know whether they are close or not we
[00:22:19.12 --> 00:22:22.88] will need to use the position of thumb y
[00:22:22.08 --> 00:22:25.44] and
[00:22:22.88 --> 00:22:27.92] index y the vertical position if the
[00:22:25.44 --> 00:22:30.96] difference between the y axis difference
[00:22:27.92 --> 00:22:33.60] between these two is very close or close
[00:22:30.96 --> 00:22:36.80] to zero then we know there is some click
[00:22:33.60 --> 00:22:39.76] operation happens and in this block we
[00:22:36.80 --> 00:22:42.16] have thumb y but we don't have index y
[00:22:39.76 --> 00:22:44.56] so what we can do outside of our while
[00:22:42.16 --> 00:22:48.24] loop we can declare a variable
[00:22:44.56 --> 00:22:50.80] called index y and then we will
[00:22:48.24 --> 00:22:53.76] set the initial value as 0 and this
[00:22:50.80 --> 00:22:56.88] value would be changed once this while
[00:22:53.76 --> 00:22:59.04] loop is running and if you get uh this
[00:22:56.88 --> 00:23:02.16] index 8 that means you are getting the
[00:22:59.04 --> 00:23:04.72] index finger tip position you will set
[00:23:02.16 --> 00:23:07.12] the index y values and it since it is
[00:23:04.72 --> 00:23:10.48] declared on top of here it will be
[00:23:07.12 --> 00:23:12.16] available anywhere inside the loop and
[00:23:10.48 --> 00:23:13.60] here we can say like
[00:23:12.16 --> 00:23:15.28] if
[00:23:13.60 --> 00:23:17.12] ah the absolute difference because this
[00:23:15.28 --> 00:23:19.20] could be like other way or this way
[00:23:17.12 --> 00:23:20.40] something like this absolute difference
[00:23:19.20 --> 00:23:23.36] between
[00:23:20.40 --> 00:23:25.76] my index y
[00:23:23.36 --> 00:23:28.64] minus thumb y
[00:23:25.76 --> 00:23:31.44] is less than like 20 or you can change
[00:23:28.64 --> 00:23:34.32] this value i want to tell like okay
[00:23:31.44 --> 00:23:36.72] print ah they are clicking something
[00:23:34.32 --> 00:23:39.20] like this click operation done and you
[00:23:36.72 --> 00:23:42.08] can here you can see like outside you
[00:23:39.20 --> 00:23:44.72] also want to see print uh say like index
[00:23:42.08 --> 00:23:48.08] y or maybe you can just copy this guy
[00:23:44.72 --> 00:23:49.44] what is the difference uh outside and
[00:23:48.08 --> 00:23:53.04] here we will print outside the
[00:23:49.44 --> 00:23:55.44] difference between the this index y and
[00:23:53.04 --> 00:23:58.00] thumb y and if they are very close or
[00:23:55.44 --> 00:23:59.52] close to 20 you will see that click we
[00:23:58.00 --> 00:24:02.00] are not doing the click but at least we
[00:23:59.52 --> 00:24:04.64] will see the print click so i am running
[00:24:02.00 --> 00:24:07.44] this guy and let's see whether this is
[00:24:04.64 --> 00:24:09.92] working so you see these these two is
[00:24:07.44 --> 00:24:12.24] coming and if i move my hand
[00:24:09.92 --> 00:24:14.08] you see uh these two
[00:24:12.24 --> 00:24:17.04] coming close together
[00:24:14.08 --> 00:24:19.60] and here if uh this absolute difference
[00:24:17.04 --> 00:24:21.76] print absolute difference these two and
[00:24:19.60 --> 00:24:22.96] i have this print accent why i take out
[00:24:21.76 --> 00:24:26.40] this guy
[00:24:22.96 --> 00:24:28.64] and then print y index is equals to four
[00:24:26.40 --> 00:24:32.96] and then print absolute difference this
[00:24:28.64 --> 00:24:35.92] this this maybe i will do like outside
[00:24:32.96 --> 00:24:38.40] and this this and then i stop this dude
[00:24:35.92 --> 00:24:40.80] i run this guy let's see whether i'm
[00:24:38.40 --> 00:24:44.32] getting something here you see outside
[00:24:40.80 --> 00:24:46.24] is like 39 the difference is closing and
[00:24:44.32 --> 00:24:48.64] if it is closing you see click click
[00:24:46.24 --> 00:24:50.88] click you see the click and if it is uh
[00:24:48.64 --> 00:24:53.28] bigger you don't see that click so let's
[00:24:50.88 --> 00:24:55.12] do it again you see this this this
[00:24:53.28 --> 00:24:58.32] coming coming coming coming if it is
[00:24:55.12 --> 00:25:01.44] coming then you see stay in nine and
[00:24:58.32 --> 00:25:04.16] once it is 9 10 7 the difference is less
[00:25:01.44 --> 00:25:06.24] than 20 you see this click is happening
[00:25:04.16 --> 00:25:09.12] so let's make it working with just two
[00:25:06.24 --> 00:25:12.00] more lines then we are pretty much done
[00:25:09.12 --> 00:25:14.80] so this last two lines is very simple we
[00:25:12.00 --> 00:25:15.68] will go to pi auto gui and tell it to
[00:25:14.80 --> 00:25:18.48] click
[00:25:15.68 --> 00:25:21.20] so once this click is done we will just
[00:25:18.48 --> 00:25:23.60] wait a few seconds so pi what are going
[00:25:21.20 --> 00:25:25.60] to we want to sleep for few seconds
[00:25:23.60 --> 00:25:28.40] maybe one second that's it we are done
[00:25:25.60 --> 00:25:31.12] with step number five so if we have done
[00:25:28.40 --> 00:25:34.56] this correctly what we will do we will
[00:25:31.12 --> 00:25:36.96] run our uh project but we will stop it
[00:25:34.56 --> 00:25:39.20] by using our hand so let's say our mouse
[00:25:36.96 --> 00:25:41.36] is somewhere here let's see mouse is
[00:25:39.20 --> 00:25:44.08] here so this is running which is good we
[00:25:41.36 --> 00:25:46.08] are raising your hand you see two finger
[00:25:44.08 --> 00:25:49.28] and by using the index you can take the
[00:25:46.08 --> 00:25:52.48] mouse little bit far you see little bit
[00:25:49.28 --> 00:25:54.88] far and it is going to and then it is
[00:25:52.48 --> 00:25:57.44] here let's do it other way around so
[00:25:54.88 --> 00:26:00.16] let's put it like this way so that we
[00:25:57.44 --> 00:26:02.88] can see this and then we can see this at
[00:26:00.16 --> 00:26:05.60] the same time to believe that this is
[00:26:02.88 --> 00:26:07.84] working so here where is our cursor is
[00:26:05.60 --> 00:26:08.64] going going going our cursor is going
[00:26:07.84 --> 00:26:11.28] here
[00:26:08.64 --> 00:26:14.48] we want to go little bit up a little bit
[00:26:11.28 --> 00:26:17.04] up close to this stop button
[00:26:14.48 --> 00:26:20.00] and then if we click it if we take our
[00:26:17.04 --> 00:26:23.60] hand together there you see
[00:26:20.00 --> 00:26:26.48] our program stopped and by using our
[00:26:23.60 --> 00:26:29.04] hand the virtual mouse now do some a fun
[00:26:26.48 --> 00:26:31.36] part of it so we can click on this guy
[00:26:29.04 --> 00:26:33.60] and we can go to any of the website
[00:26:31.36 --> 00:26:35.76] let's go we are going to maybe our
[00:26:33.60 --> 00:26:39.28] favorite amazon.com
[00:26:35.76 --> 00:26:41.92] and by using our virtual mouse i can
[00:26:39.28 --> 00:26:45.12] navigate to this website so you see this
[00:26:41.92 --> 00:26:47.84] is my hand and my cursor point is going
[00:26:45.12 --> 00:26:49.36] and i can click on like maybe this one
[00:26:47.84 --> 00:26:52.64] hand and household you see i'm
[00:26:49.36 --> 00:26:55.04] navigating maybe i'm interested about
[00:26:52.64 --> 00:26:56.88] bestseller right i'm going there and i'm
[00:26:55.04 --> 00:27:00.00] clicking and i'm going to the best
[00:26:56.88 --> 00:27:02.24] seller maybe i'm going to amazon basics
[00:27:00.00 --> 00:27:05.52] i need some basic stuff i click on this
[00:27:02.24 --> 00:27:07.36] guy i'm going there even if you want to
[00:27:05.52 --> 00:27:10.16] scroll you can just click somewhere say
[00:27:07.36 --> 00:27:13.20] i want to scroll you see you can scroll
[00:27:10.16 --> 00:27:14.96] so you can do some virtual mouse with
[00:27:13.20 --> 00:27:17.60] just how many lines of code you have
[00:27:14.96 --> 00:27:20.16] done is just 35 blanks of code
[00:27:17.60 --> 00:27:23.04] so that's all my dear friend if you
[00:27:20.16 --> 00:27:25.76] watched until this point you have to
[00:27:23.04 --> 00:27:28.16] have to check this awesome app called
[00:27:25.76 --> 00:27:30.88] programming hero you can go to the play
[00:27:28.16 --> 00:27:33.44] store and find this fantastic app and if
[00:27:30.88 --> 00:27:36.08] you are using an iphone you can go to
[00:27:33.44 --> 00:27:39.84] the app store and find this fantastic
[00:27:36.08 --> 00:27:42.88] app to learn more about python and this
[00:27:39.84 --> 00:27:45.68] project with some five steps and if you
[00:27:42.88 --> 00:27:48.64] have watched until this point uh please
[00:27:45.68 --> 00:27:51.44] please like this video subscribe to this
[00:27:48.64 --> 00:27:54.24] channel and write some lovely romantic
[00:27:51.44 --> 00:27:57.44] comment that grandma your fingers are
[00:27:54.24 --> 00:27:59.76] kissing or grandma i want to give you a
[00:27:57.44 --> 00:28:02.64] watermelon or some other gift so that
[00:27:59.76 --> 00:28:04.88] grandma would be publishing every video
[00:28:02.64 --> 00:28:07.44] in every other week that's all from this
[00:28:04.88 --> 00:28:10.88] video your grandma and i will see you in
[00:28:07.44 --> 00:28:10.88] the next video