 workshop. Here we are. It is time for this week's workshop livestream, so thanks for stopping by. Again, you may notice the continued moving around of stuff. I got the back wall patched here, moved the lockers over there. Who knows? That may or may not stay there, but there's a big area here that may end up turning into a different type of storage. We'll see. I've got a bunch of CRTs. In fact, I'm going to show you a new one I got. A bunch of CRTs that are stacked up on a double workbench I built a few years ago over there, and I might move them over here. We'll see. Maybe a video wall changed where the tools are. Who knows? But change is a foot. What is going on today? I've got a coupon code for you. I've got a recap of JV's product pick of the week, which we had on Tuesday. I have a new Circuit Python parsec coming up. We also are going to take a look at a couple of different focusing tricks in the Pie Camera library and the Memento hardware. I'm going to use some Photoshop and some Premiere to show you things that we can do with being able to essentially bracket the focusing, set steps of focusing, and then either combine those into a single entirely in focus image or be able to rack focus between things or create a pseudo-split diopter shot. We have some neat stuff. Andy, there are always more CRTs. Always. This is the panic with CRTs. If you like using CRTs, you know that their days are limited. There's no new ones being made. If you use them, you may not be able to keep using them 20, 30 years from now. They last a long, long time if they're cared for well, but there are parts. The tubes, pretty good. Some of the tubes will start to sag and not be quite as bright as they used to be. They're actually rejuvenation machines that will, I believe, burn off a layer of some of the material that the phosphors are exciting or get excited by the electron beam. There really is a thing, a CRT tube rejuvenator that allegedly works. A lot of time it's just caps, old caps that die, especially on the power transformer part of the circuit. Anyway, enough about CRTs right now, but more later. What else have also got, is that going to be it? Yeah, I think that'll be it. I'll show you. We'll do some real, I think we'll do some real live examples of some of the camera focus bracketing kind of stuff, which should be pretty fun. So first of all, I promised we have a coupon code, FocusPocus. That is your coupon code today. Oh yeah, anti-calaway degaussing ones, too. Also helpful for tubes that don't have their own. FocusPocus, right there. That is going to get you 10% off in the store today. So head on over to the great big Adafruit in the sky. It looks like that right there. This is mesmerizing. This new 1.2 meter long line green flexible LED nudes thingamajig there. That's cool. Also these double-sided analog strips. That's kind of neat. If you're doing lightsabers and things, kind of nice to have a double-sided strip. Anyway, those are some of the new things. You can always click on products and hit on the new products view all. That'll show you what some of the new stuff is in the store. And if you throw some of those things in your cart and then go and check out, you can get 10% off just by typing in focus dash focus into the coupon code slot. That'll work on goods. It won't work on software gifts or subscriptions, but on the real stuff, yes. What else? So yeah, that's coupon code. I'll remind you of that later on. Go buy some cool things. And that's how that's how we are a float here. That's how Adafruit works by selling you stuff. So please buy some things. You may like them. Next up, a little recap of my show from Tuesday. So as you may know, I have a product pick show on Tuesdays this week. It was a new USB host featherwing. So we have in the past, we have a, in fact, I found one. I have one right here. We have an existing feather with USB host built in. That's an RP2040. But that's a very specific architecture. If you want to use a different feather and you still want to be doing some USB hosting, well, then this featherwing allows you to add that on to a whole bunch of the different feathers that we have. And then plug in mice, keyboards, devices, talk serial over the USB. You can work with hard drives, flash drives and so on. In fact, that's the demo I'll show you. Here is a little one minute recap. The USB host featherwing with this paired up with your feather, you can plug in your sort of normal USB cable right into this and then have a keyboard on the other end and you're hosting the keyboard a mouse on the other end. A USB flash drive, which is pretty cool. In fact, I've got a demo I'm going to show. I have a feather M4. It's on a feather quadrupler using that. I have a little OLED featherwing. I will use that. And then we have our USB host featherwing. What I've wanted to do for a long, long time is be able to pick up random thumb drives from around my workshop and office and find out what the heck is on them without mounting them onto a computer. Plug this little USB thumb drive into the host port and immediately mounts that and starts reading the contents off for me. So these are just the names of the files that are at the root level. USB host featherwing with the Max 3421E chip. Yeah, the new CRT was in the background of that shot. I noticed that too, Andy. By the way, if you're wondering, if you're over on Twitch or somewhere and you're like, who's he talking to? There's no one in the chat. We use Discord. That is our Discord server right there. And this live broadcast chat channel is the place you want to be. To find our Discord server, you can just search for it on our website or go to adefru.it slash discord. That's our URL shortener. And that'll take you right there. And you can browse around the different channels. And the conversation during the live streams tends to be here in the live broadcast chats. So that is one place. I'm also keeping an eye over here on the YouTube. So hello, Dave Odessa, Johnny Bergdahl, Metatech. Thank you for joining us. And over in our aforementioned Discord, we've got Andy Calloway, Gary Z, Johnny Bergdahl, some nice. Hey, Steve. Okay, Iran is here. Mike P. Welcome. Thanks for hopping in the chat. Next up, hey, let's do a Circuit Python Parsec. Okay. For the Circuit Python Parsec today, I wanted to show you some fun tricks that you can do with lists. So in this example, you can see the setup here. I am creating a list, happens to be a list of strings. And these are some color names, blue, green, indigo, orange, purple, red, violet, yellow. The list there, I can then do some really efficient manipulations with to grab different items from the list, some sets of the list, grab a particular item, let's say the last one, grab the first one, shift the list around. There are a lot of practical uses for this as needs to sort data all the time. A good one is LEDs. My friend Todd Kurt, who suggested this tip, uses this type of list manipulation to deal with LED colors for neopixels. But if you take a look at the example here, what I'm going to do is I'm just going to simply run this code. It's going to run one time. So if you look in my serial output at the bottom there, when I run the code here, you can see it's going to tell us some things, and it takes a second between each one. So we can look at those. We have the whole list getting printed out, and that is this right here, blue, green, orange, indigo, orange, purple, red, violet, yellow. I am then asking for the last element. Just tell me what's the last element? The last element is the word yellow. How do I do that? I said, give me my list and then in brackets minus one. So the list and then index minus one grabs the last item in the list. If I want to grab a subset of that, a little slice of that, we can just ask for them by number. I said, you know, give me from the first to roughly the middle. So I said go from zero and then colon my list divided by two as an integer. And so that gives me this partial list here. This slice is just blue, green, indigo, and orange. If I want to ask for everything, but I want to exclude the last item in the list, we can say my list, and then in brackets zero through minus one. If I want to ask for everything, but the first element, I can just start essentially a slice that begins at something other than zero. So my list one colon and then leave off a number at the end. And it'll just go from there to the end of the list. And that's this one right here that you can see no longer starts with blue. And then this one requires a little bit of setup. What I'm going to do is create a temporary item that is the first item in the list. So my list zero, I'm grabbing that giving it a variable named temp first. And then I'm going to take my list from zero to second from the last, and I'm going to shift that one to the left. So I'm taking that range and I'm moving it to start at one. And then I can replace the last item with the first. And so that's how we get first a shift. And then that blue getting tacked back on to the end. And so that is a number of ways that you can have fun with lists inside of circuit Python. And that is your circuit Python parsec. Let me see. I wonder if I can show this example. There's a nice example here. It's going to make my screen flicker and freak out. Oh no, there we go. I'm going to open this up in quick time and just add a quick time window to the view. Hold on one second. Save that. Downloads. I hope Todd doesn't mind, but this was a cool example of using pretty much that type of list manipulation to make an animation of Neopixels. So here let's quick time movie here. And there you can see we've got a list that is just three colors, but you can see they're being moved around, swapped, the first one being told to be the last one, and so on, using a really similar technique there. And in fact, if he's around, maybe Todd can share the code for that. Oh, also a nice example from the chat from Mike P. And that is quick way to copy a list. List two equals list one, and then just colon. And so that is saying the entire list, wherever the contents are. Yeah, Neopixels, Trellis Blinkies. It's a good platform, the Neopixels for doing some Neopixel type of stuff. And of course you can add input to it. Hey Todd, Todd just showed up in the chat. So that's my tip. Enjoy. So let's see. Next up, I mentioned that I was going to show off another CRT that I got recently. So this is, this one's interesting, because this is, let me switch over to the bench view over here. So this is a really cute little, I think it's eight inch black and white CRT. And you can tell by the carrying handle, this is a portable. You can see the screen there. There's nothing on it. Only thing I can show you on it is snow right now, because this is one of these TVs that only has a tuner on it for UHF and VHF and no input. It can, you can plug antennas into it, but since there aren't really any analog over the air transmissions to speak of anymore in the TV world, you can't really tune much. I think this one, there are versions of this that tune radio, but I don't think this is one of them. So this is really meant just for UHF, VHF. And if you look at this, you can see it's got power and volume on the side here, a little earphone jack. You can switch between the bands for UHF, VHF. There's a built in speaker. And in fact, this one runs off of batteries. So it's very portable. So you can see here's the plug, we can remove that. And there are, I think, what is that? One, two, three, four, five, six, maybe nine D cells that it ran on. I haven't, I haven't tried. This is a bit corroded. This would probably need some, some clean out before it would work. Also, there is evidence here. Let's see, I can't tell this switch used. Let me try to give it a little better focus. In the battery compartment here, there's evidence of a rechargeable battery. So these little prongs here were for probably like a Nikad. There was a pack you could get to plug into this. I don't think this had charging. I think you'd charge that externally, but plug that in. So anyway, that was a portable meant to take on the road. So you wouldn't miss your favorite show or sporting event. And the conundrum with these is how to get a signal on them today. So some of these, if you look online, people will figure out ways to get an RGB signal, or in this case, it's black and white, but to get a direct signal into the the tuner, giving it what it expects to get. So I think bypass the tuner, send it the signal, the type that the tuner would send with the proper impedance and resistance. So there are ways to do that. And then the other way that's kind of interesting is to get a transmitter. So especially aficionados of really old televisions who want to still display stuff. Sorry, I'm going to get rid of some of this corrosion here. They will get TV transmitters. A popular style is called an agile modulator. And I think you can pick them up in the sub hundred dollar range for some pretty nice ones, which will give you composite inputs, in some cases maybe component inputs or S video. And then you can transmit out on one of the typical channel frequencies that this will tune in. And then you can broadcast out to a whole slew of different tuner based TVs. So I'm kind of interested in that also kind of interested in the direct route. I will plug it in just so you can have a look at the the snow gives me some idea that the tube is in pretty decent health. The picture fills the frame. Are you on? Oh, maybe maybe I spoke too soon. It was giving me a picture. Oh, okay, I hear it might take a moment to warm up. There you go. So that is this light here is going to blast that out a bit. I can turn that down. I can adjust the contrast and brightness and tuning a little bit. Let's try to dial in some clearer, more stable snow. Oh, that was pretty good right there. And I can blast the brightness up. It will behave enough. Yes, we're going to run into some frame rate issues here. But anyway, the tube fills the frame. There's no obvious distortion or anything like that. You can tell even with the snow when when that's happening. So neat little TV. I've also seen people online turn these into essentially oscilloscopes. So there's some existing examples of doing that sort of thing. But that is the new little weird quasar ACDC battery based UHF VHF television. Unplug that and set that over here. I don't know that I would pay money for it, but I got it for free. So of course here it is. Questions over in the chat thoughts in the chat. Oh, it does say on the side rechargeable batteries and some instructions on their use. Yeah, I'm not going to look for a battery for this really just just keeping it plugged in would be fine for anything I'm doing. I don't need this out out and about. I don't think Andy, why is there a tomato on the bench? That's a great question. What's this tomato doing here? Good eye. That's a good segue. I was shooting some macro photos of this tomato with the Memento camera as a test. Tomato is not a great subject for what I was doing. Maybe I'll show some images of that later. But that brings us to the main topic, project topic of the show today, which is shooting stacked focus, rack focus and sort of pseudo split diopter images, multi focus images with the Memento camera using pie camera. So let me get set up. And I'll start with let's do a I'll show you in Photoshop some examples of what we're talking about here and then we'll look at how we're doing it. So let me switch over to that view right there of the world. And I'm going to show you some photos I took using the Memento camera of a group of little Lego mini figures here. So this is I think a shot about 50 photos. I grabbed every fifth one here and we'll talk about intervals and things in a second. But this is essentially with the Memento locked in place, not going anywhere on a tripod or just sitting still. I have a photo of the nearest mini figure in focus. And here is one with the essentially the back wall there in focus that that's that little display case there of many figures is in the range of its sort of infinite focus mode. So the farthest and the nearest focus that we have. Now, a few things you'll notice this camera has a pretty narrow depth of field, which means when you're focused on something, the amount of space that is in focus before it goes out of focus as we get closer and closer to the camera is pretty shallow. They say narrow, it's a shallow depth of field, which means if we move it, let me turn all these on. So if we move that focus closer, so now we're focused on that red mini figure, you could see the next guy behind him with the vest, he's pretty, pretty out of focus. The dude back there with the wrench and the red hat very out of focus back wall, super out of focus. And so is the mini figure in front of me. Now, this is we're talking about a foot and a half, so not not a huge distance there. And so it's only maybe three inches, four inches that is a band of focus from the camera and then things fall out of focus. So different cameras with different sensors and different lenses will have and with different, essentially shutter speeds and exposure settings, a bunch of variables, will have different depths of field available. But this is in fairly natural state what the camera is going to give us is a fairly shallow depth of field, which is really cool because it means that we can do tricks like this where we can direct the eye to a particular point without moving the camera. So this is a trick used in not a trick, but it's a technique used in photography and in filmmaking to direct the eye. So if I want to focus on this guy in red there, he's now what we're paying attention to. If I focus on the guy in blue, he's what we're paying attention to. Now another important thing about the way that the lens focusing works is that focusing a lens is always in a sense moving some of the lens elements away from or closer to the sensor or the back plane or what used to be the film plane in a film camera. So you can tell as we focus further away, the whole image is changing scale. And so when I have my farthest and nearest focus, if we look at the shift here, when we're focused on the blue guy, the lens has gotten closer. And as we focus away, the lens pulls back. So we want to be able to either leave that alone and do a sort of dramatic rack focus that changes the apparent size of it, essentially the zoom of it will adjust as we focus. And this is true in film cameras as well. Or we can try to approximate something like a sort of minimal version of something called a Zolly, which is a zoom and a Dolly happening at the same time. It's a way to essentially adjust the perspective while staying put. So we can do versions of that if we were to take this camera and move it physically a little bit every time we adjusted the focus, we could get rid of this problem of the scaling. Or we can do it in software, which is what we're going to do. Because right now, if I want to take all of these slices of focus that I have and combine them to get one essentially perfect everything is in focus, physically impossible, everything is in focus with this little lens, then we got some scaling to adjust. So that's one thing we'll look at, particularly for things like macro photography, a concept of what's called focus stacking, where we are taking a series of images at different focal lengths and then combining them into a single image where everything is in focus, that's what the tomato was about. So these are kind of the two big ways that we're going to talk about using this and then we'll look at a third one. And actually, since someone posted one, here is a, there's a bunch of these in JAWS and someone posted one, a GIF in the chat. So if you watch, here's a Zolli. And I think, let's see if anyone's done a, if anyone wants to look for anything that Brian De Palma does. So Cary is a good example of a split diopter shot. There's a lot of great examples if you just look online of focus poles where rack focus changes what we're looking at, something in the background, something in the foreground, the camera otherwise doesn't move. So let's take a look at what we can do with just this sequence of photos that we've taken. So I'm going to switch actually over to Premiere for a second here. So this is, and by the way, the things I'm showing, you can do in a lot of different software, I'm happy to show Adobe products because they're what I use, but there are free and open source things that'll do these things. There are paid things that aren't the one I'm using that you love that you can use, so this is not meant to be a holy war about software. So if you look here, I have a sequence of images. In fact, let's, let's take a look at one of these. So here is a set of about a dozen or so images. And you can see the, especially towards the end here, the focus is starting to shift as I move it. You'll also notice there are some exposure and white balance shifts, and that's something I have to fix in software. Still, I'm going to lock, just like we did with the time lapse, I'm going to lock it so the memento makes some determinations about white balance and exposure and shutter speed on the first frame. And then just locks those so that we don't get that kind of flickering as they change. So let me, let's go back to where was the full one, the edit. Yeah, let's just look at this one. So this one is all of my 50 or so images. I'm just taking some pauses. It's why it's kind of chopped up this way because I wanted to pause on someone being in focus, pause on the next one, pause on the next one, and then I kind of go back through it. So these are no changes in the distance between the camera and the characters there or the subjects. This is literally that sort of zooming, you see that is what happens as you're focusing, you're moving the lens towards or away from the scene. So this is, if I play this, just a set of still frames, and then I'm holding some of them so that we can pretend that there's dialogue or something going on. So that's the natural state of the images. That's the images that we get off of the camera. And in fact, if I look at these here in this little preview, these are same images I was showing you in Photoshop. It's just as more of them. I have, I think I have all 50 of them in here. So really cool for doing this type of rack focus effect. If we want to, like I said, take this series of focal slices that are a bunch of images and combine those. I want to show you how to do that from scratch in Photoshop, and then I'm going to show you that there's some software you can use. I found a web-based solution that does a really great job of focus stacking, which is this notion of saying, I want to take a whole bunch of photos and then I want to get everything in focus by grabbing the best stuff from all these photos and combining them into a single photo. So here, let me go back to Photoshop. And I'm going to do a fresh scene here. I don't think you're going to see some of the things that I do in the interface, because I think they're considered a different window, as far as my screen capture software, but I'll explain what I'm doing. So first thing I'm going to do is run a script that will stack all of the images I tell it to into one Photoshop document with a bunch of layers. So I'm going to go and browse to the set of images that I shot and in a second here, you'll see those show up in Photoshop. But this is just kind of a batch script that takes them and just puts them each onto their own layer. So look on the side there, you should see it's just importing all of these, and I'm not doing anything fancy with it. You can do things where, since this camera was locked, I don't need to try to align them, because I wasn't wobbling around, the camera was locked down. But you can do that with this, so it's really helpful if you're trying to get a bunch of images on top of each other. It can use some feature matching to try to align them. But this right here, so that's all I've done so far. You can see I've got the series of images. I'm going to just put them into a group there to make them a little easier to deal with. And these are, as I start turning off some of these layers, you'll see the focus shifting. Now in fact, I think this is excessive. Well, I'm going to redo this with every fifth photo. Sorry, I forgot I wanted to not do that with every image. So give me one second. So I'm going to go again to my scripts, load files into stack. I'm going to go browse the same set of images, but I'm just going to pick every fifth image. So 5, 10, 15, 20, 25, 30. And this is one of the things that we can control in software when we're capturing them, is we can tell the Memento camera how many steps to adjust the focus by. We have 0 to 255 is the range that adjusts the physical focusing of the lens. The lens is moved with a little motor coil, a voice coil. So it's essentially like a solenoid pulling it back. And we can adjust the current to say where to put it. This is also used in the autofocus that we have in some of the other modes, which is cool. But in this case, we just want to manually say take a photo with far focus, now move it in 10 units, take another 10 units, take another 10 units. And so we can sort of bracket through the different currents on that motor coil. Okay, so now I have a more reasonable set of images here. You can see the focus change is bigger between them than the one I did a second ago. But this should be enough info. You don't want to probably don't want to have too much because this is enough to get each of those characters that we want in focus and focus. So we don't need to deal with more data than is necessary. So I'm going to take those just for organization purposes. I'll stick them in a little group. I'm going to duplicate the group just so I have the unaffected one as well. So the next thing I want to do is fix this issue of them being different scales. Because again, look at the first image versus the last one. And you can see that lens got pushed really close. And so it's just physically further. So this is kind of what we're going to target. When you're shooting these, you want to leave some space around the edges if you don't want to get things cut off. Because at your nearest focus, when you're pushed the furthest, you're going to lose some info from the edges compared to the very first one as you'll see here. So what I'm going to do is now run a script or a plugin feature in Photoshop that is going to automatically align those to get them scaled to the same size. So we can see the results once that runs. Let me run image or rather edit auto align layers. I'm going to use an automatic projection. Now it's going to look at these and try to figure out what warping exists, what lens distortion exists, what scaling differences exist, and it's going to try to get them all to agree. So you can see here it is now pushed in as close on the first image as it was on the last. So if I hide that first one and show that last one, you can see we now have sort of a common scaling to them. They don't appear to jump and scale anymore. So that is great. That's so nice to do that algorithmically. You wouldn't want to try to do that by hand. So Photoshop uses the auto align for that. And now we're going to use the auto blend. And so this is used originally when this came to Photoshop maybe 10 years ago. This was used to stitch together panoramic photos. So if you took a series of overlapping images, this was the tool that would match features and blend the edges. So you could end up with one big seamless panoramic photo or a texture map if you're trying to build texture maps for CG characters. It was used for that as well. So now it has a different an alternate algorithm that instead of thinking it's trying to stitch edges of panoramas, it is trying to do this exact thing, this focus stacking thing, and find the common features, get them aligned, and then it does a bunch of automatic masking. It builds alpha mats for each layer so that we see the sharp stuff only on that first image and the sharp stuff only on the final image and work through it in between. So I'm going to pick all of my layers here. I will go to edit auto blend layers. So the pop up window you can't see here, it just says panorama or stack images. I'm going to say stack images. I'll also let it do seamless tones and colors. That will probably fix some of the white balance and exposure differences that I had between them. So that's now running and it will essentially just add mats, which is a grayscale alpha channel attached to each layer that decides what part of that layer's pixels we see and which ones we see through. And look at the result! Magic! We have this perfect, there's the original, one of the originals. Let me go to the last frame of those originals in fact because I think the scale will match. So one frame of the originals was in focus near and totally out of focus far. This is the result of all of the auto blend just deciding which things are in focus. So it's kind of neat. I think it's looking for relative sharpness between neighboring pixels to decide who's in focus and who's blurry. It does some funny stuff. Remember I said the edges will get cut off. Here it actually blended some of the back layers where there was no information in the nearer layers. So this guy's got some sort of out of focus hair here on the side. So I would honestly go and crop this to just the part we need. I won't do that right now. Leave it alone. Oh let me zoom out a bit there. You can see a little bit better. And so there we go. We have just stacked a series of 20 images or 15 images or so. And in the end we have an impossible type of focus that we couldn't get from this camera otherwise. Now it's interesting to see if I turn off some of these layers you can see the bits and pieces it grabs from each layer. So it's grabbing from a few frames of that background to build what it thinks is the in focus part of that. So each frame has these matted out sections. And it's not perfect but you can also go in there and fix them if you like. You can paint out essentially with a brush the black and white matte. And in fact if I zoom the thumbnails bigger I'm going to make big huge thumbnails you should be able to see those better now. So those are those are what these mattes look like per frame. So they're these bizarre no one would do it by hand this way but algorithmically it's decided that's what the mattes look like for those to get. In framing you can see it as we get to the guy in the vest you can see there's his mat the guy in red there's his mat the sailor there's his mat and then these last few combined to make the the guy in the blue suit. So yeah it's a it's a pretty cool effect. I was talking with some people about this and one one funny thing is that to a lot of people who are used to iPhones which can do this stuff just in a millisecond in the in the background or even in live preview like 60 times a second doesn't seem like much but if you if you consider what the iPhone the what the lens is like it's a tiny little lens with a very nearby sensor so I suspect the depth of field that you get is the result of some of this stuff happening computationally. I would guess that it's pretty rare that you take a picture with an iPhone and it isn't actually bracketing a bunch of exposures and white balances and and focuses and then synthesizing those into a single image that wouldn't surprise me I don't know if that's public knowledge what things they do I'm sure there's there's some good websites out there talking about it or speculating at least but the computational photography on an android phone on an iphone and now more and more on point and shoots and and mirrorless cameras and DSLRs they're all I think taking advantage as much as they can of this type of stuff going on so that I think there's a cinematic mode right in in the iPhone which allows you to do some rack focusing things and there's probably some of this there's probably depth sensors as well I think there are some IR grids that are thrown out into the scene and and return so there's a lot going on an iphone but here we're doing it with the with the memento camera in a in a pretty neat way and you get to get your hands dirty with it and and understand how it works so yeah DJ Devon 3 mentioned this is used a lot in space photography with telescopes stacking images and in the chat last night Fedet 2 was saying they do some macro photography and I think even in microscopy focus stacking is important to be able to get a a combined series of frames into one useful image or the best image you can so I thought it would be fun to try to do a live example of this and but before I do that let's take a look at what the software is doing here this is in flux but if we go let me pull up my browser if you take a look at the latest release of the circuit python pike camera library and look at the actually the most recently closed poll request was this manual focus control with an exclamation point so lady aida did this there's a info about how I think originally the autofocus led to this but looking at how the autofocus sets the lens and then resets it later she was able to find code examples in the in the camera library that allows you to was it in ESP camera expressive camera for yet but there's like a C library I think that we're referencing it has this capacity to receive a current value 0 to 255 of essentially how much current to run through those coils that changes its position so that's now in and if we take a look at I'm going to plug the there's my memento by the way I've been talking about this but not showing it so if you're not sure what I'm talking about this is the this is the gizmo this is the camera that I used for it and you can see as teeny tiny little lens there that thing I looked at it under the microscope while I was running it through the series of stacked focuses and I can see it move about a quarter of a millimeter or something it's not much it doesn't go far but actually if you look at it really close you can see the little coil that surrounds the lens that's the magnetic coil that's that's pulling it or pushing it on its little path that it can go so I'm going to plug this in and in fact let me show it on my overhead here while we're looking at the code just because that's how I have the windows set up anyway so if we close that up let's open up code.pi that's running on here it's booting up it gets trying to get on my wi-fi and it's a little far away sorry there we go oops okay there so what we're looking at here is I've taken the existing Jeff's camera example from the library and then I've just crudely done some adjustments to it so if you take a look here most of this will look like the the existing camera code the addition here so there's additions in the pi camera library and there's additions here right here I set this to just be when I touch the shutter button this button right here it will set this variable called focus stacking to be true it prints a little message and I set the focus to be the infinite focus so it pulls it all the way back that's kind of its default state anyway but in case we left it in some other focus state I just want to start this at the extent you can however adjust this so if I say start at 127 then it is going to start it halfway which is great if you're shooting a macro photo you might want to do very small steps and start at 200 to 255 so so there's a that's kind of the manual control of this of course we're going to leave it it's all open source it's all there for you to tinker with if you want to do something fancy like set to manual focus points like push the camera tap it pull the camera tap it dial it in with a potentiometer whatever you want to do you can adjust this and I believe you'll see it in the update in the in the viewfinder update it's a small screen but you will see on there this preview is live so it'll show you what the current focus is of your scene so now if I've changed this variable focus stacking to be true it'll run this right here so it's going to do this voice coil motor that's what VCM stands for voice coil motor step is a variable it's going to be equal to the autofocus VCM step which I'm starting it at zero in this case and then we say that is going to be the minimum of 255 and so we're going to you know we'll get to 255 eventually but the minimum of 255 to the VCM steps plus the focus steps so I've got these set to five up here so that's fairly granular you could do by 10 by 15 by 20 you can do it by one you'll get 256 photos taken on your card which you may be more than you want but you know they're not really big so even at their largest size they don't take up a lot of room on the SD card so you can do that it just takes a while because between each step it has to save to the SD card so it takes a you know a little bit of time it's not not going to rip through these super fast and then as long as that value of the VCM step is less than 255 or whatever you want to step set your your you could make that a variable and say this is as far as I want to go so here's the band I'm trying to capture it will capture the JPEG so that is the first step that that means that the image that the sensor sees at full size will get captured over the SD card I'm making a little tone here and I actually have it increasing in pitch it's a little stressful actually I might change that but with every photo I have it kind of increasing in pitch just so I have this audible sense of where we are in the in the process the autofocus VCM step is set to that number so that's where it pushes it changes that value I'm putting a message on screen that just lists that number out so I can keep track of it that way as well updating the live preview and then I'm printing the just to the shell or to the ripple rather what that value is and then when we we are done we set the focus stacking variable to false we say to done done stacking I reset the focus back out to zero update the live preview and we're done so let's let's do an example just right here I'm going to set these to let's say focus steps of 20 we save that and we can still do all of the other neat stuff in here so we can if you want to turn on a filter you can change the resolution here I'll lower that resolution a little bit just make makes them actually save faster if they're smaller we do 800 by 600 normal jpeg I'll turn on the LED ring there on its lowest level and let's just while we're right here I'm going to set a couple of objects in front of the camera see what I'm doing there put that and a battery and it's good to have something real close because we do we can get very close focus on this so let me grab a grab that tomato how about okay so I'm going to just okay so just shot all those to card I was wobbling it a little bit I didn't have it locked down so these won't line up perfectly but we'll see how Photoshop does so I'm popping out the SD card I have a reader here yes let me eject the current one second that in and then I'm going to over Photoshop and bring in those images actually no we can just maybe just look at them in a quick time stack that'll make it a little faster we won't try to process these we'll just have a look at what it just did so let me go back to this view and go back to quick time I don't know if it'll let me not want me to do so from quick time I'm just going to do file open image sequence I'm going to go to the SD card I just plugged in and find those images okay and let me just share this quick time view with you on the screen capture that window quick time there we go so this is that's just scrubbing through those frames you can see I wobbled the camera a little bit but there we get a nice right here we get a pretty nice focus on the tomato and the leaf and stem there and we get a little closer even there's that circuit playground express there's the battery there's the feather back there and now we're focused beyond that that little wall there a little typewriter case you see so that's the we just kind of get a free whoop rack focus there I don't know if you can loop for quick time you see be able to set loops and things and photo and the other just in quick time here we go so here's a little loop of that oh my my broadcast software won't loop that very quickly but so you got the idea now we can also do the the combine of those if we want to we can also do a split diopter shot so that's the last thing I wanted to show and what I'm going to do for that let's uh let's come back here into the world for a second um let's see was there a question I heard a bloop bloop you can't see it did I never push that okay hold on thank you where did it go hmm hold on there we go sorry about that thank you for the note uh can't see the window okay uh here is there okay uh now you can see it thank I should I should check my output monitor not this one so there is the farthest focus you can see here's where I jiggled the camera then I kind of kept it mostly still and there it is the battery the circle playground and then tomato so this was what I say steps of 20 so that's you'd get about 10 12 photos with your full range but again you can start it closer and get a more granular set if you want but that would work well for focus stacking because the important things that we we want to see in focus are in focus in in some frames it's kind of a clunky rack focus so there you you might want to get as granular as it'll allow you okay so and thanks for the note by the way I appreciate that you can see that so now last thing I want to do is uh let's go back to the software and we'll just edit it right now I don't have any of this stuff in the UI that'll be coming but for now I'll I'll just do it directly in here so I'm gonna put my sd card back in the camera and uh what do we want to do let's do uh 20 steps still is probably good maybe 10 so this will give it more photos more granular it's a smaller step that it's taking that in and uh everything else I think looks good we'll start yeah we'll even start at the farthest focus okay so this is good so let me just save that and then over here what I'm going to do is I've got uh you can see I have some figures set up here I've got a little Pikachu uh I've got a I'm not going to touch him because he's a bobble head and I don't want to move around the photo but I got chicken little bobble head there and then I've got a Lars back there and so what I want to do is align them in the photo uh and then we'll take a look at oh in fact you know what let's do just two let's just do chicken little and Lars because this is a more typical so he's gonna bobble hopefully he'll settle down uh this is a more typical situation where a split diopter uh shot would be used and so this and I didn't explain too much a split diopter shot is actually a um typical film camera lens with a secondary half lens so it looks like a semi circle in front of it that allows you to have two different focuses it's essentially two half lenses that are both sending light to the film or the the sensor and so this is one that uh I posted uh let me you know I'll do it in a in a browser window let me go to my browser window and show you a nice example here of carry split diopter here's a nice example um so I can get that one here's these are all these are not possible right these these subjects are real far from each other only one should be in focus uh this one's beautiful you can really really see it here um and you can see so Carrie and her tormentor there are both in focus in the scene um there's a sort of a telltale blur where the edge of this physical glass lens that's been um sort of threaded onto the front or mounted onto the front of the the real lens the original lens um there's a little bit of optical distortion there so you end up with a sort of blurry line between them um but this is instead of something like a rack focus where we'd look at one character and then look at the other so let's see both of them clearly at the same time which again typically in film this was done as a practical and camera effect more possible to do with some clever software types of things and giant depths of field make it conceivable uh sensors are really sensitive now lights are not so hot so you can get a lot of light on a scene but anyway that's a that's a pretty famous example of a split diopter so if we want to approximate that all we really need is two frames that are going to be in the proper focus we'll shoot a bunch so we can pick between them and then we can create a gradient mask between them so that we can see the two at the same time that's a simple thing to do in in your image editing software uh so camera i'm gonna switch to this view here um and let me so i can see lar's back there lar's is pretty dark so let's get some light on him too do i have a easy to place light maybe this one and yeah up lighting lar's is great because that's ominous so chicken little and lar is both in the frame there uh let me see if i can use a little tripod mount so i've mentioned these these are these like six dollar iphone tripod mounts i like these these are working pretty well for just clamping the memento in and then they have a typical one quarter thread for for tripod and it'll actually work pretty well on its own okay so there we go so i've got them both in frame uh i'm gonna hit go and then i'm stepping away this is 190 210 220 230 240 250 and then it stops because it can't go beyond 255 uh and then it resets the lens uh and so now i can take this out my sd card put it into my reader and we'll come back to photoshop and what did i do did i add that yeah i have that screenshot capture there uh let's see all this yeah let me push that there we go okay so again i'll just load them into a stack we're not gonna um we don't need the software to do this first we're just going to do two frames so we don't need to get all these layers uh so this is really easy uh so i will bring them all in for convenience load files into stack browse yeah a red gel for larris would be perfect okay so i'm going to grab those frames uh remember i shot these at 800 600 or i kind of forgot that i'd set it that low so these are these are not super high res but we can we can do this with full res uh okay so there is about let's see what's the best larris focus maybe that we'll say that's the best larris focus and then we'll find the best so that is 67 i'm just gonna add a a mask to that that currently doesn't mask anything out um and fill it with black so it will mask that image and then i can go find a good chicken little frame so maybe that one uh so this won't be super dramatic just because i don't think i got a great larris focus there but uh if we take zoom in closer uh so right now this is the uh frame that has larris in focus and it should have chicken little autofocus uh so if i look at that whole frame larris goes in but chicken little goes out so what i'm going to do is just simply create a mask the whole frame here that is only the larris half so i'll fill this with white okay so now you can see there's larris there's chicken little you can see there is a um because of that actual physical distance of the lens changing there is a line there so we're just gonna to sort of mimic that split diopter we're gonna um just give us a gradient right there so that essentially blurs between those two uh and in fact i can just use a blur so let's do a large Gaussian blur right there okay and so now that helps to soften that transition between the two and now that's terrifying right now we have the that was the uh just chicken little in focus there's both larris and chicken little in focus like a proper horror film uh so i hope you enjoy that okay that is it so that covers our split diopter uh we have the uh focus stack to put everything in focus which was this example here uh and then we have our rack focus here as those read in in in back to the best guy again so three cool techniques that didn't you know strictly speaking exist in the camera but are all possible because we can in circuit python go in and tell that voice coil what to do and when to take pictures so i can imagine you could get really sophisticated with this uh you could probably do an interface that says i want to uh take eight pictures and these are the exact focal distances i want on them maybe even do uh some of the math uh from from the camera uh in fact you uh you may hear if you don't if you don't know the terms of some people on a film set uh there's a person on a film set called a focus puller and one of the things that they do is often take a tape measure and measure the distance from the uh film back of the camera to a spot so they know what to dial in everything at um and if they're doing rack focuses things like that you can do the math to figure out so you could certainly put little focus pulling info on the on the camera and say okay i'm going to take eight photos and these are the distances that i want in focus uh we know what the depth of field is on it so you should be able to get that pretty accurate and away you go with your own uh sort of customized film uh focus stacking camera all right uh i mentioned i will give you this again this is our uh coupon code for today so if you want to get 10 off in the store just head on over to adafruit.com throw some things into your cart and on the way out in the coupon code type in focus dash focus because this has been a whole bunch of focus focus uh thank you everyone so much for stopping by uh what do we have coming up i don't know if scott is doing a deep dive tomorrow i think he plans to if available he has um daycare pickup duties for his kid so sometimes that uh kids can throw wrenches and plans i know uh and then i believe we're gonna have a foamy guy deep dive on saturday if that plan is still um moving ahead and then we will come back around next week with a new product pick of the week we will have 3d hangouts we'll have show and tell ask an engineer uh and more so thank you everyone for stopping by for adafruit industries i'm john park this has been john park's workshop i will see you next time bye