File size: 7,704 Bytes
17e2002 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | 1
00:00:00,660 --> 00:00:01,060
High.
2
00:00:01,110 --> 00:00:03,450
OK so you've made it to a first mini project.
3
00:00:03,570 --> 00:00:07,060
This is using a webcam to create a Live sketch of yourself.
4
00:00:07,110 --> 00:00:10,190
So let's quickly run this app and see what it does.
5
00:00:10,200 --> 00:00:12,860
So this is me here talking in my bedroom here.
6
00:00:13,570 --> 00:00:20,400
This is me weaving around and this is me here with my cell phone being charged at the moments you can
7
00:00:20,400 --> 00:00:21,290
actually see the corner.
8
00:00:21,300 --> 00:00:22,850
It's quite cool.
9
00:00:22,910 --> 00:00:24,200
This is a sketch.
10
00:00:24,840 --> 00:00:26,490
It works pretty well generally.
11
00:00:26,520 --> 00:00:31,550
I mean you can play with the problem is in a app to get it better coding or better to do with this.
12
00:00:31,560 --> 00:00:34,260
So let's see exactly how this is implemented.
13
00:00:34,920 --> 00:00:35,280
OK.
14
00:00:35,310 --> 00:00:36,390
So here's a code.
15
00:00:36,480 --> 00:00:37,970
Well let's get you up.
16
00:00:38,040 --> 00:00:43,140
It's fairly basic although we do introduce some new concepts here and the first thing we introduce is
17
00:00:43,140 --> 00:00:48,220
creating a function that will open C-v all image processing function called sketchier.
18
00:00:48,660 --> 00:00:54,720
If you're unfamiliar with functions imagine a function being basically a group of commands here that
19
00:00:54,720 --> 00:00:58,410
we call we and we run the sketch commander over here.
20
00:00:58,440 --> 00:01:03,270
So a sketch actually does a bunch of processes here and returns an image for us.
21
00:01:03,270 --> 00:01:07,660
So it actually combines multiple layers of image processing and this Rutins a final output.
22
00:01:07,660 --> 00:01:08,570
So it's pretty cool.
23
00:01:11,210 --> 00:01:15,680
The second thing I want to introduce you to is actually using the webcam now using a webcam and you
24
00:01:15,680 --> 00:01:17,590
can see these is actually quite simple.
25
00:01:17,840 --> 00:01:24,230
What we do here we actually run this initialising video capture function here and it basically creates
26
00:01:24,230 --> 00:01:30,800
an object called a cap cap here can be read now which is a cap that read here and what it does it pulls
27
00:01:30,800 --> 00:01:32,710
an image from the webcam.
28
00:01:32,720 --> 00:01:38,210
However if you run it out of a loop it just pulls the image at a time and nothing else.
29
00:01:38,210 --> 00:01:43,880
So what you want to do is have cap dot reader running in a loop and this loop runs continuously pulling
30
00:01:43,880 --> 00:01:45,480
images from the webcam.
31
00:01:45,500 --> 00:01:52,760
It should be pulling a film right off your webcam which is usually Tuti freedoms a second sometimes
32
00:01:52,760 --> 00:01:54,400
it's more than VMS's it's less.
33
00:01:54,420 --> 00:02:02,510
But generally it's either between 24 and 60 and kept it read it was written Regt read is basically just
34
00:02:02,510 --> 00:02:04,370
a boolean that defines true or false.
35
00:02:04,370 --> 00:02:06,440
What it does was run successfully.
36
00:02:06,440 --> 00:02:12,530
However the real meat of this captain read function is frame Freemans the actual image captured from
37
00:02:12,530 --> 00:02:20,450
the webcam and Freemans what we pass to a sketch function here and lastly just two lines of code here
38
00:02:21,020 --> 00:02:27,500
basically tells us that it would be loop only breaks when we pressed Enter key so CB2 that we had previously
39
00:02:27,500 --> 00:02:33,950
was a zero before took any key in I'm just introducing No we can actually define we'll wait for special
40
00:02:33,950 --> 00:02:35,040
commands.
41
00:02:35,060 --> 00:02:40,560
So in this case when you press the Enter key a routine key it breaks this loop.
42
00:02:40,610 --> 00:02:45,710
One important thing to remember when using a webcam is that we need to do captive release Ottaway is
43
00:02:45,720 --> 00:02:51,740
again what happens in open Sivy is that it hangs and actually locks up your terminal and you have to
44
00:02:51,740 --> 00:02:53,990
go to Kunaal restart Suranne it again.
45
00:02:55,760 --> 00:02:56,010
OK.
46
00:02:56,020 --> 00:02:59,240
So let's take a look at a function here we'd find a sketch.
47
00:02:59,320 --> 00:03:04,330
This is actually doing to both have to work and where we keep all the image processing open CV stuff
48
00:03:04,330 --> 00:03:05,220
here.
49
00:03:05,230 --> 00:03:06,910
And it's actually a very simple function.
50
00:03:06,910 --> 00:03:08,150
So let's take a look here.
51
00:03:08,440 --> 00:03:12,560
So what it does we tear the frame from a webcam here.
52
00:03:12,640 --> 00:03:19,100
It's a sketch we didn't convert it into grayscale image and then we apply a glossy and blue to that
53
00:03:19,150 --> 00:03:20,260
image here.
54
00:03:20,260 --> 00:03:27,250
The gospel is basically to just smooth and clean up any noise in the image because webcams aren't very
55
00:03:27,700 --> 00:03:29,500
high quality in most cases.
56
00:03:29,500 --> 00:03:31,430
So they do produce a lot of noise.
57
00:03:31,510 --> 00:03:37,920
So once that image is blurred we passed that to a county as your member canny edge direction algorithm
58
00:03:38,720 --> 00:03:40,690
and is it a Tressel's we set here.
59
00:03:40,890 --> 00:03:41,760
These truffles.
60
00:03:41,850 --> 00:03:45,320
Please feel free to edit and play with them as you as you see fit.
61
00:03:45,450 --> 00:03:49,150
They can they can give you different results in different lighting conditions.
62
00:03:49,230 --> 00:03:52,560
These are what I found optimal to my TS and my lighting conditions.
63
00:03:52,560 --> 00:03:55,380
But you may find something different.
64
00:03:55,380 --> 00:04:01,290
And once we have county you remember County was a black background with white edges.
65
00:04:01,590 --> 00:04:05,500
However I was trying to illustrate more like a pencil and people type thing.
66
00:04:05,780 --> 00:04:12,230
So which is why I use fresh binary invis to invert and Threshold the county edges.
67
00:04:12,360 --> 00:04:16,240
Now we could have to use some other inverse functions here.
68
00:04:16,260 --> 00:04:20,970
And you will remember we could have used a bitwise NOT doing it.
69
00:04:20,970 --> 00:04:25,940
However the reason I use the Trishul function here is that we can actually play with this here.
70
00:04:25,980 --> 00:04:27,760
This was a Trishul parameter.
71
00:04:28,080 --> 00:04:30,220
So it gives you some more flexibility here.
72
00:04:30,600 --> 00:04:37,190
And what this does here this creates a mask and then this function returns mass back to back here.
73
00:04:37,500 --> 00:04:44,230
So it does actually block of code here actually is a variable itself that's true to and from and from
74
00:04:44,230 --> 00:04:48,790
the sketch function which is how it's we can show it to him Show function.
75
00:04:49,590 --> 00:04:55,980
So that's basically our lives sketching up something very simple and so you can actually play with it
76
00:04:55,980 --> 00:04:56,760
on your own.
77
00:04:56,970 --> 00:05:02,050
Feel free to actually add more effects as you see fit.
78
00:05:02,060 --> 00:05:02,510
Thanks.
|