9:59:59.000,9:59:59.000 Okay, so, we are now ready to move on 9:59:59.000,9:59:59.000 to something, pretty, [br]different and exciting 9:59:59.000,9:59:59.000 um, and what that is, is[br]looking at moving images 9:59:59.000,9:59:59.000 so we spent all this time saying, okay, [br]I could have a blank PImage 9:59:59.000,9:59:59.000 and i could figure out some [br]interesting algorithmic way 9:59:59.000,9:59:59.000 to set all the pixels of that image 9:59:59.000,9:59:59.000 or, I could have an image thats coming [br]from a file, like frog.jpg 9:59:59.000,9:59:59.000 and i could load that image, and i'll [br]have all the access to all the pixels 9:59:59.000,9:59:59.000 and i could draw it on the screen [br]and i could manipulate it 9:59:59.000,9:59:59.000 and do all sorts of stuff[br]what if, however, 9:59:59.000,9:59:59.000 we could have a camera, [br]this is my weird drawing of a camera 9:59:59.000,9:59:59.000 and what if i could pull in a live image[br]from a camera into my Processing sketch 9:59:59.000,9:59:59.000 What could I do with that? what if I had a[br]you know, a movie file? 9:59:59.000,9:59:59.000 could I pull in that movie and play back [br]that movie in my Processing sketch? 9:59:59.000,9:59:59.000 speeding it up, slowing it down, [br]going in reverse 9:59:59.000,9:59:59.000 how could I-, how does all this [br]stuff work? 9:59:59.000,9:59:59.000 How do we make this happen? So, let's [br]first just take the basic transition from 9:59:59.000,9:59:59.000 flat image file to camera and the way [br]that we're going to do this 9:59:59.000,9:59:59.000 is with Processing's Capture object[br]So, the Capture object, is part of, 9:59:59.000,9:59:59.000 Processing's video package[br]Now, I just realized, 9:59:59.000,9:59:59.000 there's kinda a crucial component to this,[br]if you are using, and again, this part of 9:59:59.000,9:59:59.000 the video, sadly, is going to just [br]become obsolete in a little while 9:59:59.000,9:59:59.000 but, if you are using the 3.0 alpha series[br]and, hopefully, there will be a beta soon 9:59:59.000,9:59:59.000 or a final version, this will be true for [br]all the 3.0 version's of Processing 9:59:59.000,9:59:59.000 Let's come over here and look, uh, here, [br]if i go to, Import Library 9:59:59.000,9:59:59.000 let me just zoom in here[br]Import Library >> Add Library 9:59:59.000,9:59:59.000 and i pull this up, you won't, by default,[br]have the video library, so I'm going to 9:59:59.000,9:59:59.000 search under Processing, and this is what [br]you're looking for, you wanna find 9:59:59.000,9:59:59.000 in this contributions manager, 'Video' [br]library by The Processing Foundation 9:59:59.000,9:59:59.000 so, in order to run any of these examples,[br]or, to work with live video 9:59:59.000,9:59:59.000 or recorded movies in Processing, you need[br]this particular video library 9:59:59.000,9:59:59.000 in all the previous versions of Processing[br]prior to 3.0, this library came with 9:59:59.000,9:59:59.000 Processing, but its quite a large... large[br]library, also it's maintained and updated 9:59:59.000,9:59:59.000 on a separate schedule, so by pulling it [br]in separately, all you need to do is, 9:59:59.000,9:59:59.000 Hey! Whoa! I haven't actually- Amazing![br]I forgot that i just did a fresh install 9:59:59.000,9:59:59.000 of Processing here, so, this is-, [br]we're going to test this out 9:59:59.000,9:59:59.000 you just wanna hit this 'install' button [br]and, uh, while it's downloading 9:59:59.000,9:59:59.000 and should be ready to go, and now,[br]we're going to have this library! 9:59:59.000,9:59:59.000 yeah! and then it'll say 'remove', so, if[br]you don't have the video library, 9:59:59.000,9:59:59.000 make sure you get it (button click)[br]okay, back over here! 9:59:59.000,9:59:59.000 Once you have the video library, you [br]now have access to the Capture object 9:59:59.000,9:59:59.000 you also have access to the Movie object 9:59:59.000,9:59:59.000 so, Capture being live video from some[br]camera, that's connected to your computer 9:59:59.000,9:59:59.000 Movie object, you'll use for video files,[br]that you're loading and playing 9:59:59.000,9:59:59.000 back in Processing, so 9:59:59.000,9:59:59.000 here's the thing, the thing that's [br]the most wonderful about this 9:59:59.000,9:59:59.000 is that, both of these things are PImage's[br]essentially, all the functionality; image, 9:59:59.000,9:59:59.000 pixels, width, height, copy[br]any piece of functionality, you learned, 9:59:59.000,9:59:59.000 and practiced, and did with PImage, you [br]could do exactly the same functionality 9:59:59.000,9:59:59.000 with Capture and Movie 9:59:59.000,9:59:59.000 the only thing that's different, is when[br]you load a PImage, like frog.jpg, 9:59:59.000,9:59:59.000 those pixels are never gonna change, [br]unless you change them, right? 9:59:59.000,9:59:59.000 that file, that image is a [br]flat, static image 9:59:59.000,9:59:59.000 those pixels are the pixels 9:59:59.000,9:59:59.000 you could do all the same operations! but[br]with a Capture object or a Movie object, 9:59:59.000,9:59:59.000 those pixels might be changing according [br]to some schedule, of course, 9:59:59.000,9:59:59.000 we have total control over that schedule, [br]we could say, give me fresh pixels from 9:59:59.000,9:59:59.000 the camera, or stop giving me fresh [br]pixelsfrom the camera, or, 9:59:59.000,9:59:59.000 advance the next frame of the movie, or,[br]don't advance the next frame of the movie, 9:59:59.000,9:59:59.000 so this is an added piece of the puzzle, [br]that we'll be able to work with 9:59:59.000,9:59:59.000 as we start using these classes, so, let's[br]sort of, uh, let's look and see how this 9:59:59.000,9:59:59.000 would work, there's a couple little[br]nuances here, so, i'm back over here, 9:59:59.000,9:59:59.000 and i'm in a sketch, so, this is just a, [br]kind of a simple processing sketch 9:59:59.000,9:59:59.000 that I think we did at some point in an [br]earlier video, I'm loading an image, 9:59:59.000,9:59:59.000 I'm drawing it on the screen, [br]I'm using a couple things; 9:59:59.000,9:59:59.000 #1 - you can see I can dynamically resize[br]the image as i draw it, using the mouse, 9:59:59.000,9:59:59.000 or I could also tint it, meaning, [br]change its color, so, 9:59:59.000,9:59:59.000 what I want to emphasize in this-, [br]just first part of this video, 9:59:59.000,9:59:59.000 is let's make this the Capture object from[br]the camera, I have a laptop in front of me 9:59:59.000,9:59:59.000 its not all magic, let's get that image[br]from that camera, and let's see that there 9:59:59.000,9:59:59.000 and do all the same stuff for it, [br]so, instead-, the first step is, 9:59:59.000,9:59:59.000 instead of a PImage, I wanna say, [br]Capture and I'm gonna say video 9:59:59.000,9:59:59.000 now notice, as soon as I do that, I get [br]an error message, it says, um, 9:59:59.000,9:59:59.000 if I look at the errors, you can see, [br]the class Capture does not exist, 9:59:59.000,9:59:59.000 now this needs a little bit of work here,[br]but it's actually giving me a suggestion 9:59:59.000,9:59:59.000 which is nice, this is-, Capture and Movie[br]are both part of that Processing video 9:59:59.000,9:59:59.000 library that we just installed, so even [br]though I've installed the library 9:59:59.000,9:59:59.000 I have to-, in my code, make an explicit [br]reference that i'm going to use it, so, 9:59:59.000,9:59:59.000 I'm just gonna-, Processing will [br]add this for you automatically, 9:59:59.000,9:59:59.000 in a bunch of different ways, [br]but I'm just gonna do it manually, 9:59:59.000,9:59:59.000 so I just need to have an import statement[br]at the top; import processing.video.*; 9:59:59.000,9:59:59.000 now I have my Capture object, now,[br] 9:59:59.000,9:59:59.000 you might think, you would say [br]something like: "I said loadImage(), 9:59:59.000,9:59:59.000 so, loadCapture (should work) or [br]something? createCapture, connectVideo, 9:59:59.000,9:59:59.000 startVideo", um, the way that [br]this works however, is, 9:59:59.000,9:59:59.000 there is no function like that, we need to[br]use the tools and syntax of 9:59:59.000,9:59:59.000 object oriented programming, [br]so lets come back over here 9:59:59.000,9:59:59.000 and if I have a video object, the syntax [br]is to say, I wanna make a new... 9:59:59.000,9:59:59.000 Capture object, and I need to figure out,[br]what goes in there, so, 9:59:59.000,9:59:59.000 what might be some parameters [br]that you need 9:59:59.000,9:59:59.000 when you're about to connect to [br]the live camera? 9:59:59.000,9:59:59.000 maybe you might say: [br]"Ah! camera over there! 9:59:59.000,9:59:59.000 I would like a very high resolution image"[br]or "a very low resolution image" 9:59:59.000,9:59:59.000 so, some parameters we're going to [br]put in there as the width and the height 9:59:59.000,9:59:59.000 of our requested, uh-, images [br]that we'll get from the camera 9:59:59.000,9:59:59.000 another piece of information that we [br]might put over here, is... frame rate 9:59:59.000,9:59:59.000 do i want to get images from the camera [br]at, 30 frames? 60 frames? 120 frames? 9:59:59.000,9:59:59.000 15 frames? 9:59:59.000,9:59:59.000 now, with both of these-, frames per [br]second, so, with both of these, 9:59:59.000,9:59:59.000 certain cameras are only [br]going to support 9:59:59.000,9:59:59.000 [br]certain resolutions and [br]certain frame rates, 9:59:59.000,9:59:59.000 so, a lot of this really depends [br]on what you've got, 9:59:59.000,9:59:59.000 and I'm going to show [br]you a way to figure out 9:59:59.000,9:59:59.000 what your camera makes available to you 9:59:59.000,9:59:59.000 but generally speaking, 640x480, 30 FPS,[br]those are, kinda good numbers to use, 9:59:59.000,9:59:59.000 and in fact, this (meaning >> FPS) [br]is an optional parameter 9:59:59.000,9:59:59.000 you're just gonna get the default frame [br]rate, if you don't request a specific one, 9:59:59.000,9:59:59.000 which is usually 30 frames per second 9:59:59.000,9:59:59.000 now, there's another argument [br]that needs to go in here 9:59:59.000,9:59:59.000 and this is one of those tricky one [br]that appears, when you're using-, 9:59:59.000,9:59:59.000 a lot of times when you're using a [br]Processing library 9:59:59.000,9:59:59.000 One of the things we need to do, is, we[br]need to say: "A Capture object camera", 9:59:59.000,9:59:59.000 "you're (referring to camera) going [br]to have new images available" 9:59:59.000,9:59:59.000 "you're looking at the room, [br]you're looking at me," 9:59:59.000,9:59:59.000 "you know where I want you [br]to give those images?" 9:59:59.000,9:59:59.000 "I want you to give those images to me" 9:59:59.000,9:59:59.000 who's 'me'? [br]this particular Processing sketch, 9:59:59.000,9:59:59.000 'this' sketch, 9:59:59.000,9:59:59.000 so the keyword 'this' needs to go in here, 9:59:59.000,9:59:59.000 now we could have a much longer discussion[br]about what the keyword 'this' means 9:59:59.000,9:59:59.000 and Java, and then we can sit here and[br]complain for a while 9:59:59.000,9:59:59.000 about how confusing these, like, archaic[br]concepts, and like, old-fashioned 9:59:59.000,9:59:59.000 languages like Java are 9:59:59.000,9:59:59.000 but for-, we don't really need to [br]worry about it too much 9:59:59.000,9:59:59.000 to make all this stuff work, we just need [br]to remember the keyword 'this' goes there 9:59:59.000,9:59:59.000 and I think it's kinda useful, to kind of [br]think about the fact that 'this' 9:59:59.000,9:59:59.000 is referring to this Processing sketch 9:59:59.000,9:59:59.000 I don't want the camera images to go to[br]some other program on the computer 9:59:59.000,9:59:59.000 I want them to go to this Processing [br]sketch, and we're telling the library that 9:59:59.000,9:59:59.000 this-, this happens in a lot of other ways[br]behind the scenes in Processing, 9:59:59.000,9:59:59.000 but you don't always have [br]to use that keyword 'this'