Skip to 0 minutes and 7 seconds Let’s demonstrate some of these principles in MATLAB. I’m going to create a point in the world and it’s going to be at coordinate 0.2 metres in the X direction 0.3 metres in the Y direction and it’s going to be 5 metres in Z direction. Now Z is the direction along the axis of a camera we call the optical axis of the camera. This is a relatively small object five metres away from the camera and a world point is always a column vector so there it is. Now I’m going to create a camera object in fact a central camera object which does the particular projection that we just learned about and it’s got a focal length of eight millimetres.

Skip to 0 minutes and 51 seconds So here we created the workspace now a central camera projection object. This object has got quite a lot of methods and we’ll have a look at some of those. But first thing I’m going to do is to use this camera object and I’m going to project my world point capital P to the image plane, which you see here that we have got some very small numbers. These numbers are less than half a millimetre. We’ve taken our view of the world and we’ve made it much, much smaller and projected it onto the image plane. This is where the piece of film would be or this is where the digital camera chip would be.

Skip to 1 minute and 27 seconds In this projection there’s no notion of pixels we’ve just taken image in the world and it’s described in terms of size and its distance in units or metres. We’ve projected it to the image plane and this is talking about the size of the image also in units or metres; a very small number of metres. Now let’s turn this into a digital camera let’s introduce the notion of pixels. We’re going to create a new camera object. Basically recycle this line and we will tell it that the pixels are ten microns on a side so the pixels are square ten microns wide ten microns high. And their image plane has got a resolution of one thousand and twenty four square.

Skip to 2 minutes and 8 seconds This is a mega pixel camera. Now if we look at the parameters of our camera object we see here we can see the focal length. Here we can see the size of pixels, the number of pixels, 1024 x 1024 exactly what we entered on the command line. And this parameter the principle point which is where the optical axis pierces the image plane is smacked in the middle at coordinate 512, 512. Now that I have my digital camera object, we can redo that projection that we had before project to world point P and this now is the coordinate of that point in units of pixels.

Skip to 2 minutes and 46 seconds Another method of the camera object is to actually plot these on a graphical image plane and here we can see where that world point has been projected to on the digital camera’s image plane. So now the methods we can look at the cameras intrinsic parameters. Now this is the intrinsic parameter matrix; this is the overall camera projection matrix. We can pass an additional option into the project function. First argument again is our world point and now I’m going to shift the camera a little bit. Now I’m going to tell it to shift the camera 0.1 metres in the X direction given the camera’s coordinate frame that’s a shift of 0.1 metres to the right.

Skip to 3 minutes and 32 seconds Not going to move it in the Y or in the Z directions so now what we see is that the projection is different. And we would expect that, we see that the U coordinate has been reduced from 544 to 528 and that’s what we would expect if we move the camera to the right we would expect the image plane coordinate to move a bit to the left. Instead of translating the camera we could rotate the camera so we can rotate the camera around the Y axis.

Skip to 4 minutes and 3 seconds Now the Y axis points downwards so if I do this rotation of 0.1 radians around the Y axis that’s essentially rotating the camera towards the right and if we do that here’s the projection again and as we would expect if I rotate the camera a bit towards the right the pixel in the image will move a bit towards the left on the image plane. Let’s consider a more complex example, one where there are multiple points in the world.

Skip to 4 minutes and 33 seconds To create multiple points in a grid pattern now I’m going to use the toolbox function mkgrid and I want a 2x2 grid and the points spaced on 0.2 metres centers and I want the center of the grid to be at a coordinate 1, 2, 0. So this is a grid in the XY plane, the center of the grid is offset 1 metre in the X direction and 2 metres in the Y direction and all the points have got a Z coordinate of zero. So here are the set of points that I have just created in order to view these four points which lie on a ground plane I’m going to create a new camera.

Skip to 5 minutes and 13 seconds It’s a central projection model camera again. I’m going to set default camera parameters so this is default values for focal length image plane size and pixel size. I’m going to explicitly give the pose of the camera so our four points are lying on the ground plane so in order for my camera to be able to see them it needs to be somewhere up high looking down so the first thing that I’m going to do is to place the camera 4 metres above the ground.

Skip to 5 minutes and 43 seconds So this is a translation of 4 metres along the positive Z axis and then I’m going to rotate it around the Z axis by Pi on three radians and then I’m going to rotate the camera around the Y axis so it points down at the ground. So just rotate it around the Y axis by pi radians. Bare with me I’ll work this example out and these numbers should give something like the right result. First thing we’re going to do is to project those 4 world points onto the camera’s image plane and here we have the coordinates of those points. So they clearly lay within the field of view and we can actually have a look at those four points.

Skip to 6 minutes and 26 seconds And we can plot those and that’s what the image plane looks like. So they’re just in the edge of the field of view of our camera, which is looking down. Now let’s try and get a 3D understanding of what’s going on here so I’m going to create a new figure. I’m going to call it figure two and another method on the camera object we just created is called plot camera.

Skip to 6 minutes and 47 seconds What that does it to render it’s a 3D model of a camera into a graphic and the other thing that I’m going to do is to add to these graphic the 4 world points given my capital P I’m going to render them as the little spheres with a radius of 0.5 metres each so created this little scene, turn the grid on to make it a bit easier to see. If I turn on my 3D rotation tool I can spin this around. Here we can see what it looks like, here are the four points on the ground plane now then I created using the grid function.

Skip to 7 minutes and 21 seconds And up the top we can see the camera and we can see the axis of the camera. Camera is a little bit small. We can zoom in and have a look at the camera there is it, there we can see its x, y and z axis, zoom in a little bit more perhaps and we can see there, it looks a little bit like a camera. It’s a box with a cylinder on the front. These are just the few examples of the many things that you can do using the camera classes within the toolbox.

# Modelling cameras in MATLAB

The linear algebra approach we’ve discussed in the previous steps is well suited to MATLAB. Let’s look at some Toolbox functions that can simulate what cameras do.

This video demonstrates how to model a camera in MATLAB. You’ll also have the opportunity to try a MATLAB activity in the next step.

© QUT 2017 unless otherwise noted. All rights reserved. CRICOS No. 00213J