Put 3D Objects in Any Photo

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back to another default cube cg matter tutorial and today I'm gonna be showing you how to do camera alignment all inside a blender and in case you haven't seen the cg matter tutorial I'm just gonna start fresh what do I mean by camera alignment well suppose that you have a photo that you took on in this case my phone I just took a photo of the street and this is the photo we want to use for camera alignment meaning that I want to use blender to put like something like a monkey into scene some 3d objects you know in the scene with the picture we took as the background but before we get to this step we have to do what's called camera alignment or maybe camera calibration depending on what you want to call it meaning that we need to make a digital camera that matches the position orientation focal length and everything else of our real camera meaning that in blender for the scene I actually created a camera that is the same height above the ground facing the same direction has has the same amount of zoom same amount of focal length and that's why the monkey actually looks like it's there if any of those things are wrong it will be on the street but it just won't look correct so this is a tutorial explaining how to do it but in blender meaning that you're not gonna be paying for software like cynthaiz which lets you do it pretty easily but you have to pay or an external program like f spy so all in blender and it's a pretty unique technique I don't think I've seen it before but before we get into it there is just one trade-off you need to know about so to be able to do it entirely in blender the only sacrifice we're making is that instead of one photo you're gonna need to take two right kind of like a stereo pair so these are kind of slightly offset from each other you see one's kind of to the left ones kind of to the right kind of like you're blowing in your eyes and you see your thumb moving you just need to take two photos and the second photo is gonna give us enough information to to do our camera alignment on the first photo so as long as you have two photos you are going to be good to go so let's open up blender and before I show you the real technique something you might you know kind of be tempted to try as you kind of go into your camera maybe you set up your background image and you're thinking oh I can do this manually I don't know why I need any kind of a fancy technique or as Kompas about there's come possible so you might just put this in the background and think to yourself okay I can do this myself like you try to reorient it but what you're gonna notice is if you're trying to reorient it manually like right now it kind of looks like the floor is level with the ground the way I've like oriented our scene but stuff like the focal length the height above the ground all this is incorrect because we didn't do it in a mathematical sense we're just eyeballing it which might be fine but generally it's gonna make your renders just look a bit off so here's how you do the method what we're gonna do I'm gonna start a new scene make that full screen this is what you see when you open up blender and hopefully I gave a good introduction of what we're doing here you're gonna go over to the movie clip editor and this is where we're gonna be doing some motion tracking again this is why we need two photos we're gonna do a two camera track but don't only use it the first frame for camera calibration or alignment and before we do anything fancy let's just set our color management over to standard so that our images come in in the correct color space and they don't look weird so standard and let me also save the file because I know I know I'm gonna get a crash this is the luck that I've been having recently so once you're in the movie clip editor you are going to import in your two images as if they were an image sequence which they are it's just a two frame long image sequence so click shift click you have both of them open clip meaning that if you go right left right left you're going to frame to frame one frame to frame one you have a two frame image sequence and what we're gonna do is hit set scene frames to go from frame 1 to 2 instead of 1 to 250 right we want to shorten our project and prefetch to load both of those into memory ok so now we're gonna be doing our motion tracking and because of the fact that it's only 2 frames we don't need to really do like automated tracking we can do it manually since we're only doing one picture two pictures we're not going 180 frames down or something like that so I might actually use that approach instead of conventional tracking so I think let's start off like that at least so what I'm gonna do is I'm going to add a tracker which you can do by ctrl-clicking hold ctrl click and we have our tracker and you click right arrow to go one frame down and then we're just gonna move it you can click L to Center by the way we're just gonna move it to the same location so left frame right frame you can see it's the same thing and by the way you can use this window to this window right here to see if it's kind of in the same spot it's kind of a zoomed in magnified version so that's a good tracker lock that in what we need to do is put at least eight of these trackers down to get our camera solve and you can see like I did there you can do it manually cuz you can just eyeball it fairly accurately or you can use normal tracking techniques but you might get some issues there if your left and right photo are very far apart but let me try that method so for this next one let's do tracking I'm gonna use a fine for those of you who don't know what all this is I did a four hour series on it so it's it takes a while to explain but a fine basically means we're gonna be looking for not just changes in location of our feature but also kind of like pseudo perspective kind of like shearing and stuff like that not as good as perspective but a fine is almost the same so for this one let's try to put a tracker here which we can scale up to get this whole feature in here all dust to get our search box make that very very big because again there's a big change between left and right well see if that works so track you go one frame forward or instead of hitting this button alt right arrow let's see if it does it it's gonna take a while to process because you know big images but you can see did that pretty well so you can lock that tracker and now we have two of them again we need six more so for some of these I'll do manual tracking for some of them I will do you know tracking tracking so I'm gonna pick features that are in different places of the image both in 2d and 3d meaning that 2d right this ones in the middle this ones on the top so that's just where it is on the rectangle of our image and 3d meaning these are in the foreground this one's in the background right you want to have variety in both of these cases okay so let's try to get a bit more going on over here I'm just picking areas of high contrast and again the reason you might be asking you know why are you not tracking right you're in the motion tracker why are you kind of doing this manually again I find it almost just as fast to do it manually because it's only two frames because setting up our search box and everything can take almost as much time honestly and I think this kind of highlights the process of what what it takes for camera alignment it doesn't take much normally you use again something like US Sen thighs or F Spy and those have you draw lines all over all over your image so it's kind of like the same thing but almost with more freedom because instead of drawing lines we're just putting dots and you know your scene won't necessarily always have lines in it like lines that are parallel to the x-axis or the y-axis right but you're always gonna have just random dots and features which is why I actually like this method quite a bit so already we have one two three four five six seven so let's just get one more I'm thinking one somewhere over here to get like medium somewhere in between foreground and background middle ground there's got to be a good name for that is that the same dot I think so so let's just Center that and hopefully me showing you the whole process is making it super clear what you need to do okay so here we have a trackers which is the bare minimum of what you need we're gonna try to do a solve if it doesn't work running we're gonna need to put a nine third sound tracker but we will see so once you have all your trackers go over to the solve panel normally I advise people to kind of ignore keyframe a keyframe B and just kind of enable this but in this case we don't have to pick you know random numbers and do all this thinking right keyframe is gonna be one keyframe B is gonna be - there are no frames outside of that so even if you don't know what keyframe a and B are just set it to one and two for now and let's try to solve for our camera motion and you see we already got a decent solve with a solve air of 0.55 generally you want under one under a pixel so already we have something that's probably a correct or very approximate solution but since we are using the camera tracker it can actually refine it can refine for focal length meaning that we now have a method not only to get our location rotation of the camera right but also focal length which is something you could not I ball manually so we are gonna set this to focal length and we're gonna start off with 0.55 let's refine and we've already dropped our solve error to point essentially point two which isn't you normally if this was a camera track that you have a whole shot point to is excellent it's a very good track and if I didn't do this manually and use the tracking to go from frame 1 to frame two I'm sure we could get this under point one honestly so if you have a small number here anything under like 0.5 once you refine you probably have the correct solution okay cool so now that we have our camera solve let's open up the 3d viewport and we want to take this data and throw it in here so we can get our camera in the correct position to do this we are gonna hit set up tracking scene which you can see if we go into our camera it looks like it already did all the work for us but that is not necessarily true we still need to align this to the floor but you can see we have a camera with the correct aspect ratio this thing is the background and everything's good so now what we need to do is kind of like a somewhat fury a ting step in blender because it takes longer than I wish it did but we need to set this plane which is the supposed to be the ground we need it to be the ground for our camera track which is kind of a hard thing to think about but all you need to do is click three different trackers on your ground plane so when you set your a trackers I guess set three of them to be on the floor or if you're doing a wall have three of them beyond the wall you know whatever you want and set that to floor and you can see that already it kind of looks like it's on the floor it's kind of oriented weirdly but when we did that let me undo when we selected these three so again quick shift quick shift quick floor it gave us some a reorient did our scene really it reorient did our camera so that it satisfies the condition that you know this is on the floor okay cool so hopefully even if you don't know a lot about camera tracking you are already following and let's just do a bit more to help us out we can pick one of these trackers one of the three and set this to be our origin which I guess it already was so centered if we pick something else it'd go further into the background further into the foreground depending on what you pick and we could do a bit more in here but the rest of this I'm gonna go with the manual approach and by the way lately I've had there we go lately I've had blender crash whenever I bring that window up which I guess I should report as a bug I don't know it's really up with that hopefully we can avoid it I'm not gonna mess with it again we'll just go to modelling go to our camera view and it's essentially the same thing as if we had compressed this window doesn't matter okay so at this point we have it on the floor and it's correct but you kind of want just just because you know you're a human you want everything oriented nicely into it's whatever you want stuff parallel we need to move and rotate this to get things looking good and we're not gonna move the plane because then it's gonna be off the origin which is not convenient instead instead we want to move the camera so instead of moving the scene around the camera camera around the scene okay how do we do that well you select your camera and you can do that by selecting you know the rim there and you kind of have to think backwards so you could hit Gy to grab and move it along the y axis and if you move it to the right it's actually gonna shift everything left and vice-versa you got to think about it it's kind of like looking in a mirror but we can just change the origin by moving along the X and y axis absolutely not along the z axis because that's going to change the elevation of it we don't want that we want it to be on the floor so we can recenter we can scale and if you hit s you're gonna notice that nothing happens that's because we want to scale to the 3d cursor which means the world origin in this case so you can see scaling moves it further closer and further away from our you know center so you can scale to do that or in this case you could actually scale off the objects depending if you want real world scale or not in this case I'm just gonna forget about that and scale it like this but you can scale the objects instead and then the nicest thing is we could rotate about it's going to be the z axis z axis to align our x y-axes with our scene so you can see this align across the what's the word for this concrete this kind of crack I'm gonna make my x axis parallel to that so I'm just rotating along the z axis until I feel like it's matching because I want that to be my x axis on the scene and then we can just kind of recenter our origin and you can see that it's still a bit off just fix that a bit and the nice thing about this is you're not messing with cynthaiz you're not messing with that spy you can just there's nothing to import right you can just mess with things right and blender and everything integrates it very nicely but one thing to notice I suppose forgot to go into full-screen one thing to notice I suppose is that technically what we did here is a camera track a very short one just for two frames meaning that we can actually go to two different perspectives on this so we've kind of done our camera alignment on two frames so you can use either picture but again if you want alignment on one photo you need to get that complimentary stereo photo to give you enough information to do your camera track so you can use either photo but if you really only want the first one and you don't want the camera to be moving and all that you don't want the animation what you're gonna do is you're gonna select your camera go to constraints and constraint to F curve which is basically gonna take the animation of the camera and moving left to right and bake it into keyframes and then all we have to do is click our keyframes on the first frame invert with control I do eet meaning that the camera never moves but the background still does so if you want to fix that you go to background images and then let's see you could just load in the picture so you can just go to image open and then choose shot one for me that's what it's called and boom there you go now you have a camera that stays still the background stays still etc and you could do all your integration of a monkey or whatever it already created a shadow catcher and everything for us when it did that a set up tracking scene so you can see we have this very nicely I mean the lighting is really bad because we like match the lighting to our scene and you know you could do that right so right now it's just kind of like this lamp above it whereas really we have the Sun on an overcast day but you can see how from here I got the monkey you know I just rotated it lit it better so that we have nice shadows and everything and yeah so hopefully you enjoyed this camera alignment tutorial I tried my best to explain it to the best of my ability not an ASMR this time by a popular demand of the patreon but speaking of patreon that's where I said going to if you enjoy these tutorials and you want to support this channel which I highly highly appreciate because it wouldn't be possible for me to do tutorials full-time in any capacity if it wasn't for patreon if you want to donate and you have the means to do so please please head over to the patreon you're gonna get benefits beyond just your donation right you get stuff in exchange sometimes they give tutorial files sometimes they give early access for different stuff so sometimes it's a sneak previews sometimes have actually uploaded exclusive videos that some of the some of them are memes some of them are good you know depends what it is I highly value anybody who first of all is willing to do that and second of all has the means to so patreon exists anyways I hope you enjoyed this free tutorial I was very excited when I thought up to this idea it's not like new information but I think I'm the first one to kind of formalize it into a tutorial so I hope you enjoyed it I enjoyed recording it and in some sense that's all that matters so who cares if you enjoyed it hope you did thanks for watching guys bye bye
Info
Channel: Default Cube
Views: 65,600
Rating: undefined out of 5
Keywords: blender, tutorial, 3d, vfx, cg, cgi, object, motion tracking, camera alignment
Id: aknsCszvMdA
Channel Id: undefined
Length: 17min 11sec (1031 seconds)
Published: Tue Apr 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.