Vision Project Report PDF
Vision Project Report PDF
Abstract:
The main problem in the robotic vision is, to identify the object and extract the position
information from the image that where in the real world the object will be. I will be solving the
same problem in the MATLAB as well as practically on the worksheet.
The worksheet will be consists of three different colors and different shapes having circles and
rectangles. On this worksheet I will perform the experiment after extracting the information in
MATLAB and then I will compare my results in the worksheet. I will take the image of this
worksheet, import in the MATLAB and applying algorithms, and then I will be able to exactly
tell where the red circle will be on the real worksheet.
After getting the real world coordinates for the desired colored shape then I will command
twolink robotic arm to move to the exact location through the inverse kinematics.
INTRODUCTION:
In industries robot has to interact with the different shape and colored object to perform
industrial task. In industries robot must have capability to perform artificially in their
environment.
The main motivation of this project is that to find the real world coordinates from the camera or
vision sensor attach in the environment of the robotic system and then giving that world
coordinates to the robot to move their end-effectors to that exact location in the real world.
This is the main part of the vision in robotics to manipulate the image coordinates (u,v) to world
coordinate(x,y).
The determination of real world coordinates has many applications in computer vision including
robot positioning, object reconstruction and measurement [1].
First of all we will try to make simple experiment to check the accuracy of our solution of
finding the real world coordinate from the image coordinates.
OBJECTIVES:
The objectives of this project is to finding the real world coordinates from the image coordinate
taken from the camera or vision sensors, in real world the robot knows and understand the world
coordinates rather than pixel coordinates and there are the huge difference between the pixel and
world coordinates .
Camera take image of the robotic system environment and capture this as the image having (u,v)
coordinates, so there is a relationship between the image coordinate to the world coordinates and
is known as camera matrix, this matrix includes the intrinsic and extrinsic properties of the
cameras. Our goal is to find the camera matrix of our laptop webcam by comparing the world
coordinates and the image coordinates.
LITERATURE REVIEW
how images are formed?
The process of image formation in a camera involves a projection of the 3-dimensional world
onto a 2-dimensional world surface. The depth information is lost and we can no longer tell from
the image whether it is of large object in the distance or a smaller closer object. This
transformation from 3 to 2 dimensions is known as perspective projection.
The image formation geometry for a thin convex lens is shown,
The rays converge on the origin of the camera frame {C} and a non-inverted image is projected
onto the image plane located at z=f. the z-axis intersects the image plane at the principal point
which is the origin of the 2D image coordinate frame. Using similar triangles we can show that
point at the world coordinates P=(X, Y, Z) is projected to the image point p=(x,y) by
X=f , y=f
MODELING A PERSPECTIVE CAMERA:
We can write the image plane point coordinates in homogenous form
or
Where
tilde=homogenous quantities
C is the 3x4 matrix known as camera matrix
= pixel cordinates
here first matrix on the right side of the equation shows the scaling/zooming characteristics of
the camera and next to this matrix is used to convert 3-dimensional quantity to 2-dimensional
quantity.
Now, if we project the world camera points to the image plane, the image plane is made up of
small grids (u,v) called pixels.
by convention the origin is at the top left hand corner of the image plane. So,
ρw and ρh are the width and height of each pixel respectively and (u0, v0) is the principal point.
we can write starting equation in term of pixel coordiantes as
we can further expand the camera matrix because there must be the pose of the camera involved
in the maping of the points.
K=it is the internal parameters of the camera like pixel values and the focal length
Extrinsic paramerters contain what is the pose of the camera, it is the external parameters of
camera. Pose conatains Rotation and translation of camera.
By combining these two parameters we get the camera matrix which maps the real world points
to the image coordinates.
it is very difficult to find the camera matrix from the basic principles because of the lack of
information about the camera intrinsic parameters, thus we can estimate this matrix by doing
some calibration process.
This camera matrix is independent of the scaling factor, if we multiply by any number and then
after finding the world cordinates to the pixel cordinates this number is cancells out and thus we
can write above equation as
POINTS ON THE PLANE/ PLANER HOMOGRAPHY:-
If we are observing the plane or paper in the real world from the camera then we know that all
point on the plane have z=0, because of the 2-D plane. Thus equation becomes
When camera matrix multiply with z=0 of world coordinates then the entire 3rd row of camera
matrix becomes zero, we don’t need 3rd row in this case.
central matrix is then known as homography matrix and it is denoted by H, which maps the
points in the plane to the points in the image.
There are 8 unique numbers in Homography matrix.
we need at least 4 points on the plane and their coresponding point in the image to find the H
matrix.
By finding the planer homography matrix we can do the inverse also to find the real world
coordinates from the image cordinates.
TWOLINK MANIPULATOR:
When we get the world coordinates from the image coordinates, we then command the twolink
manipulator to move to that point. For this function to accomplish, we will need the inverse and
forward kinematics equations and also some dimensions of the robot, so the following are the
robot description,
L1= link 1 length =15cm
L2=link 2 length =15 cm
2R manipulator
INVERSE KINEMATICS:
FORWARD KINEMATICS:
x=L2*cos(des_th1+ des_th2) + L1*cos(des_th1)
y=L2*sin(des_th1+ des_th2) + L1*sin(des_th1)
We will use robotics toolbox in MATLAB to create and move the twolink robot.
DH-TABLE of twolink robot
First of all I took the print of this worksheet and then took the image through my laptop webcam
as shown below,
Now I have the actual vision worksheet and the image of the worksheet. I want to map the vision
worksheet image pixels (u, v) to the real vision worksheet coordinates (x, y).
The basic steps for mapping image coordinates to real world coordinates are
1. Find all mark the sequence of the points so that points must be consistent between the
real worksheet and in the image.
2. Find the center points (X, Y) by ruler of all the nine blue circles in printed worksheet. As
I have measured all the points so the points are given below, we need at least 4 points but
for better estimation we will compare 9 points (cm)
x1=25.2 , x2=13.2, x3= 1, x4= 25.2, x5= 12.8, x6= 1.3, x7= 25.2, x8= 12, x9= 1.4
y1=1.3, y2= 1.3, y3=1.3, y4=12, y5=12.4, y6=12, y7=20.5, y8=20.7, y9=20.5
In matrix form
x=[x1 x2 x3 x4 x5 x6 x7 x8 x9 ; y1 y2 y3 y4 y5 y6 y7 y8 y9]
3. Find the centre points (u,v) of all nine blue circles in the image through MATLAB ,I have
computed the pixels also, the values are shown below,
p= [uc1 uc2 uc3 uc4 uc5 uc6 uc7 uc8 uc9; vc1 vc2 vc3 vc4 vc5 vc6 vc7 vc8 vc9]
p= [812.58 440.79 109.58 790.08 432.46 100.71 783.76 403.78 104.155; 632.44 614.77
609.01 291.088 296.78 307.13 45.65 57.11 69.46]
4. We have now the pixels coordinates and the world coordinates, we can now find the
Homography matrix, the matrix which can map the pixel coordinates to the world
coordinates, this can be done easily in the MATLAB robotics toolbox by peter corke.
5. Once we have the Homography matrix we can now find the inverse problem, i.e. we can
now find the world coordinates from the image coordinates.
6. I have find and compared three objects world coordinates (red rectangle, green rectangle
and top left corner red circle) and test on the real worksheet by drawing the twolink
robot.
7. Once we have (x,y) values then through inverse kinematics we will find the joint angles
for twolink manipulator and then command the robot to move to the point by forward
kinematics in MATLAB as well as on the vision worksheet.
8. You can do this process to any colored and any shape objects on the vision worksheet it
will exactly map world coordinates.
RESULTS:
1. Pixels of each blue circle is computed in MATLAB
REFERENCE:
1. “Real World Coordinate from Image Coordinate Using Single Calibrated Camera Based
on Analytic Geometry” by Joko Siswantoro, Anton Satria Prabuwono , and Azizi
Abdullah.
2. “Robotics, Vision and Control Fundamental algorithms in MATLAB” by peter corke
3. “Detecting planar Homography in an image pair” by Etienne Vincent and Robert
Laganibre
4. “A MATLAB toolbox for vision and vision-based control” by peter corke
APPENDIX
1. I have written “getColor” function to easily detect color in MATLAB.
function color = getColor(im, clr, thr)
%im=image stored, clr= ”red/green/blue” , thr= threshold for image
im=igamm(im,'sRGB');
Y = sum(im,3);
redChroma = im(:,:,1) ./ Y;
greenChroma = im(:,:,2) ./Y;
blueChroma = im(:,:,3) ./Y;
switch(clr)
case 'red'
color = redBinary;
case 'blue'
color = blueBinary;
case 'green'
color = greenBinary;
otherwise
fprintf('Invalid color option. Use red, blue or green in single quotes only.');
end
2. for finding the center of nine blue circle I have written the .m file and the code is shown
below,
%findingCenters%
% first of all find the Centroid of the blue circle to compare with the real worksheet
points%
im=iread('sheet.jpg' ,'double');
idisp(im);
prompt = 'Enter the color name'; %enter blue here%
q = input(prompt,'s');
b=getColor(im,q,0.45);
idisp(b);
[label, m] = ilabel(b);
idisp(label, 'colormap', jet, 'bar') %shows the the unique color to the unique region
%select the label numbers of the blue circles whose Centroid points are required%
%circle 1= label 13
%circle 2= label 11
%circle 3= label 12
%circle 4= label 4
%circle 5= label 5
%circle 6= label 6
%circle 7= label 1
%circle 8= label 2
%circle 9= label 3 %
%for circle 1 %
figure
blob = (label == 13);
idisp (blob)
[v,u] = find(blob);
about (u)
umin = min(u)
umax = max(u)
vmin = min(v)
vmax = max(v)
plot_box(umin, vmin, umax, vmax, 'g')
m00 = mpq(blob, 0, 0) %area of th region in units of pixels
uc1 = mpq(blob, 1, 0) / m00 %centroid in U pixels
vc1 = mpq(blob, 0, 1) / m00 %cenroid in V pixels
hold on;
plot(uc1, vc1, 'gx', uc1, vc1, 'go');
hold on;
%for circle 2 %
figure
blob = (label == 11);
idisp (blob)
[v,u] = find(blob);
about (u)
umin = min(u)
umax = max(u)
vmin = min(v)
vmax = max(v)
plot_box(umin, vmin, umax, vmax, 'g')
m00 = mpq(blob, 0, 0) %area of th region in units of pixels
uc2 = mpq(blob, 1, 0) / m00 %centroid in U pixels
vc2 = mpq(blob, 0, 1) / m00 %cenroid in V pixels
hold on;
plot(uc2, vc2, 'gx', uc2, vc2, 'go');
hold on;
%for circle 3 %
figure
blob = (label == 12);
idisp (blob)
[v,u] = find(blob);
about (u)
umin = min(u)
umax = max(u)
vmin = min(v)
vmax = max(v)
plot_box(umin, vmin, umax, vmax, 'g')
m00 = mpq(blob, 0, 0) %area of th region in units of pixels
uc3 = mpq(blob, 1, 0) / m00 %centroid in U pixels
vc3 = mpq(blob, 0, 1) / m00 %cenroid in V pixels
hold on;
plot(uc3, vc3, 'gx', uc3, vc3, 'go');
hold on
%for circle 4 %
figure
blob = (label == 4);
idisp (blob)
[v,u] = find(blob);
about (u)
umin = min(u)
umax = max(u)
vmin = min(v)
vmax = max(v)
plot_box(umin, vmin, umax, vmax, 'g')
m00 = mpq(blob, 0, 0) %area of th region in units of pixels
uc4 = mpq(blob, 1, 0) / m00 %centroid in U pixels
vc4 = mpq(blob, 0, 1) / m00 %cenroid in V pixels
hold on;
plot(uc4, vc4, 'gx', uc4, vc4, 'go');
hold on
%for circle 5 %
figure
blob = (label == 5);
idisp (blob)
[v,u] = find(blob);
about (u)
umin = min(u)
umax = max(u)
vmin = min(v)
vmax = max(v)
plot_box(umin, vmin, umax, vmax, 'g')
m00 = mpq(blob, 0, 0) %area of th region in units of pixels
uc5 = mpq(blob, 1, 0) / m00 %centroid in U pixels
vc5 = mpq(blob, 0, 1) / m00 %cenroid in V pixels
hold on;
plot(uc5, vc5, 'gx', uc5, vc5, 'go');
hold on
%for circle 6 %
figure
blob = (label == 6);
idisp (blob)
[v,u] = find(blob);
about (u)
umin = min(u)
umax = max(u)
vmin = min(v)
vmax = max(v)
plot_box(umin, vmin, umax, vmax, 'g')
m00 = mpq(blob, 0, 0) %area of th region in units of pixels
uc6 = mpq(blob, 1, 0) / m00 %centroid in U pixels
vc6 = mpq(blob, 0, 1) / m00 %cenroid in V pixels
hold on;
plot(uc6, vc6, 'gx', uc6, vc6, 'go');
hold on
%for circle 7 %
figure
blob = (label == 1);
idisp (blob)
[v,u] = find(blob);
about (u)
umin = min(u)
umax = max(u)
vmin = min(v)
vmax = max(v)
plot_box(umin, vmin, umax, vmax, 'g')
m00 = mpq(blob, 0, 0) %area of th region in units of pixels
uc7 = mpq(blob, 1, 0) / m00 %centroid in U pixels
vc7 = mpq(blob, 0, 1) / m00 %cenroid in V pixels
hold on;
plot(uc7, vc7, 'gx', uc7, vc7, 'go');
hold on
%for circle 8 %
figure
blob = (label == 2);
idisp (blob)
[v,u] = find(blob);
about (u)
umin = min(u)
umax = max(u)
vmin = min(v)
vmax = max(v)
plot_box(umin, vmin, umax, vmax, 'g')
m00 = mpq(blob, 0, 0) %area of th region in units of pixels
uc8 = mpq(blob, 1, 0) / m00 %centroid in U pixels
vc8 = mpq(blob, 0, 1) / m00 %cenroid in V pixels
hold on;
plot(uc8, vc8, 'gx', uc8, vc8, 'go');
hold on
%for circle 9 %
figure
blob = (label == 3);
idisp (blob)
[v,u] = find(blob);
about (u)
umin = min(u)
umax = max(u)
vmin = min(v)
vmax = max(v)
plot_box(umin, vmin, umax, vmax, 'g')
m00 = mpq(blob, 0, 0) %area of th region in units of pixels
uc9 = mpq(blob, 1, 0) / m00 %centroid in U pixels
vc9 = mpq(blob, 0, 1) / m00 %cenroid in V pixels
hold on;
plot(uc9, vc9, 'gx', uc9, vc9, 'go');
hold on
H= homography(p,x); %we get the homogenous matrix that relates the pixel values to the
real coordinates%
3. once the Homography matrix is achieve we can now find the real coordinates of any
colored and any shape object from the image, the code is below
im=iread('sheet.jpg' ,'double');
idisp(im);
prompt = 'Enter the color name';
q = input(prompt,'s');
b=getColor(im,q,0.45);
idisp(b);
[label, m] = ilabel(b);
idisp(label, 'colormap', jet, 'bar') %shows the the unique color to the unique region
prompt = 'Enter value of the seperation';
x = input(prompt);
blob = (label == x);
idisp (blob)
[v,u] = find(blob);
about (u)
umin = min(u)
umax = max(u)
vmin = min(v)
vmax = max(v)
plot_box(umin, vmin, umax, vmax, 'g')
m00 = mpq(blob, 0, 0) %area of th region in units of pixels
uc = mpq(blob, 1, 0) / m00 %centroid in U pixels
vc = mpq(blob, 0, 1) / m00 %cenroid in V pixels
hold on;
plot(uc, vc, 'gx', uc, vc, 'go');
p1=[uc
vc];
x1=homtrans(H,p1);
xd=x1(1) %x-coordinate of the desired object
yd=x1(2) %y-coordinate of the desired object
4. Now we have x,y values of the desired object, now I want my twolink manipulator to
move to that desired x,y point.