 So, now we're back to the live chat again. So, Alyssa's going to talk about face morphing, so off you go. I mean, I don't know how you get from there to there, but I guess we're going to find out. Being Alyssa. So good morning everyone, my name is Alyssa. I'm a Python jobs group three nights developer here in Singapore. So today I'm going to talk about face morphing. All the culture today is written in Python 2.7. Someone might give up and ask you slash a face walker and you want to check it out. So I think today is we're going to answer two questions. One, given two images, how can we create a walking sequence from one image to another image? The second one is how can we then create average base from all those images? And I'm going to answer that in just four little simple steps. Step number one, the locator. For a lot of computer vision tasks, there's a really popular library called OpenCV. So I've just leveraged off of that. OpenCV has these hard cascade classifiers where you can quickly detect faces and eyes and an image. But for this specific task, I've used datum. And that builds on top of OpenCV and it leverages on the face detection there. But it also looks at the peaks in a gradient orientation histogram. What it basically does in the end is if you input an image, it will output you 77 key face points of the image. So here you can see like the end to the eyebrows, the end to the eyes, the tips on your nose. Really distinguishable features are, you know, 10.2. Step number two is the aligner. Our images are all going to come in sizes, spaces of different locations. So we need to resize them, send to the faces, add any borders if it's too small, and then prop them all out into the desired output size for the morphing systems. So this one's fairly straightforward. Step number three is the actual morphing. So to do that, if you remember in step one, we had all these key face points. What we have to do here is triangulate them. And there's a really popular technique called deloined triangulation. For the computer scientist in the room, this runs in 10 long in time. And in Python, there is one function called, let's do this, using the sci-fi library. You just go sci-fi.spatial.bloging, passing an array of the xy points, and it will magically spin you up an array of triangulations. So each row will contain three indices, which will point to the corners of your triangle. So you have a really nice set of triangulated face mesh now at the end of the step. The actual morphing though, we're not skipping the mathematical stuff, but the general gist here is you have 83 points in the triangle, you have another three points in the destination dimension. So from three points to another three points, there is an f5 transformation matrix that you can easily calculate in linear algebra. Once you have this matrix for a triangle, you multiply it with any set of input points, and it will transform it to a destination point. So instead of every single triangle, it will just map it to its associated triangle on the destination image. At the same time though, we also have to do a binary interpolation, and that looks at its neighboring pixel values to determine its final color value. And the reason we do that is so we have a smooth gradient between the triangle and the face, otherwise we get this, like, a triangle in the destination. So at the end of this process, what we'll get is mesh number one, going to mesh number two. And with that, we can then do the morphing, which is the actual morphing. We have our input face mesh, which is our starting mesh. We have our destination face, and we have our ending mesh. And you can imagine that from one point to another point, we will have a straight line. So we can sort of locate as many points in between as we want, which means that we can create as many as immediate meshes to have this transition of start to end mesh. So the morphing sequence is now, let's work from start image number one to the next consecutive image, and then you go all the way through all the way to the end image. So if you keep morphing all the way, you'll get this nice morphing sequence, and I will demo that in this next slide here. So I have got this morphing. And it's sort of morphing back and forth, 60 frames, 30 frames per second. If you want to morph through more images, you can also just supply the folder image here. I have Star Wars, and it's just picking up all the image files here. You can jpeg and pink files, and it will just walk through all of them automatically. And if you don't want to have a video, you can just put the plot option, and you can just plot it, or you can save all of these individual frames into a folder. And you can have as many as you want in between here. I just have eight to fit it on this slide. The second question we wanted to answer today was, how can we create an average face? So it turns out we use the exact same three steps. Okay, we align, we walk the face, but they all walk to this one mesh. And once they all walk to this one mesh, you overlay all the mesh together, and you create an weighted average so that you have this one new average face. So here you just input a folder name. You have faces with four images. You can supply as many as you want. I have one where I did 85. It actually came up quite nicely. The trick of this, though, is if the faces are not facing forward, it will look really, really funky and weird. So I'll have to fix that somehow. You can see jump over to repository, because I documented a lot of the stuff over there. The face morph for repo, as I mentioned, is built in pattern 2.7, openTV, NumPy, SciPy. So the first part here is the morphing. Okay, supply is source and destination image for the image folder. I have a whole bunch of other options here where you can have a customized width, five, number of frames you want, 20 seconds, save to folder, create a video or plot it. And the second part is to create average faces from all of the images in a folder similar to supply width height. I also have a blending here, which I didn't show. I'm still experimenting with that so that you can blend a face that you finished onto another person, so you have like Sally or John kind of thing. And I'm experimenting with various blending algorithms that I haven't settled on one. So here are the steps. I've just documented it here so that if you go to the repo, you get an idea of it. And this was one of the first ones that I made. I created it in John L. Fish, which is a very fun slide and so on. And yeah, that's the one thing I'm excited for. This one here is just for Jake. I created the repo, plotted it, and this one, this was the average faces. It's made out of A5 images. They're pretty high resolution images that came out quite nicely here. Mixed genders as well. And yeah, you can generate documentation. I will just quickly, very, very, very quickly show you. Everything is located in this transform folder, and they are broken up into exactly, like the blame is like the locator, the aligner, the walker, the blender, the plotter, whatever. And I just want to give a shout out to a really, really nice tool. If anyone wants to build a command line utility in Python, there's this thing called DOCOP. You just describe how you want your command line utility to look like, and it will consume all this and have it available to you as an array. And these are just the key value pairs. So it's insanely beautiful and nice. So to consume it, you just go armed with just something that the person passed in. And I just hop back. That's all I have today. Thank you very much. Okay, okay. Your hand was actually the first. Do you want to say quickly that the transform matrix for doing the morph sequence, that's one matrix that deals with the entire, oh, with the triangle. So how do you keep the triangles together? So they're always detected at the relatively same location. To the face. To the face, it's the same. So you know from mapping this point to that point on the first face. On the mapping itself. It's always the same. So we have, we know which triangles to walk over. Do you want to say together as a, you want to say it together? Yes. Yes. You want to stay together? Yes, you want to stay together. And you have a different transformation matrix to go over and create a morph sequence. Yes. Thank you very much. Is there some tool available where you can calculate the metric, how far away two faces are from each other? That's me enough. I mean in terms of how different are they two types. Oh, how different? To get like a face recognition problem. You can, yes, actually. So I didn't think of that, but I guess you can. But the thing is your face point will look different if you have your mouth open or if you're shocked. Right. So it might not be the best way to do face recognition, but it could be a nice quick first pass. I guess to detect from any round faces to long faces. Yeah, it could be a nice first pass. We'll do it though. Can you do the same without the... That's my next thing. So the thing is I'll have to create a mesh that goes outwards as well all the way around so that they can walk, say, an entire human body over. It's a bit more challenging because I'll have to have the same points per human body. But yes, I will look at that next. Running times. Running times. It takes about one to two seconds for one to walk through another image. Much less than that. Average of the image. So you just create an average of four images. I try to make it as quick as possible. I spend a lot of time trying to optimize the matrix transformations and watch parts of the video. The running research that does that, but no, this was purely fun. So there was no research assigned to these fantasies. But yeah, there are a few reasons that you get expressions. What's an attractive face. Things like that. Do you have an image? We said something like you actually got an average face out of about 185 people. So can you show that face? I'm very interested. Okay, I know. Yeah, that's the thing. It does look normal. And that's the whole part of the research as well, is that his average face actually turns out to be quite normal. I think it's still associated with a lot of it. So the 85 faces, they came from here. These are pretty high resolution, from the images and if I stack them all together, that was the face at the back. No beard on that face. Yeah, there's a beard, exactly. What does that say? Glasses and beards and things will still get preserved. You just try to be faded out as your average as well. Other questions? Okay, let's thank Lassie.