-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trab3_Bule.m
58 lines (41 loc) · 1.67 KB
/
Trab3_Bule.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
clear all
close all
clc
% run('Calibracao.m');
% close all
% clc
cameraParams = open('cameraParams.mat');
%Get the intrinsic matrix
IntriMatrix = cameraParams.cameraParams.IntrinsicMatrix;
cam = webcam;
squareSize = 24; %in mm
[verts, faces, cindex] = teapotGeometry;
verts = verts.*15;
verts = verts*[1 0 0;0 1 0;0 0 -1];
maxi = max( verts(:,3));
verts(:,1) = verts(:,1)+3*24; %posição inicial em x
verts(:,2) = verts(:,2)+1*24; %posição inicial em y
verts(:,3) = verts(:,3)-maxi; %posição inicial em z
while(true)
% Acquire a single image.
rgbImage = snapshot(cam);
rgbImage = undistortImage(rgbImage, cameraParams.cameraParams);
bwImage = imono(rgbImage);
%imagePoints = icorner(rgbImage);
[imagePoints,boardSize] = detectCheckerboardPoints(rgbImage);
worldPoints = generateCheckerboardPoints(boardSize, squareSize);
%Calculate the extrinsic matrix
[rotationMatrix, translationVector] = extrinsics(imagePoints,worldPoints, cameraParams.cameraParams);
P = cameraMatrix(cameraParams.cameraParams,rotationMatrix,translationVector)';
PontoInicial = [worldPoints(1,1),worldPoints(1,2)];
vertsX = [verts , ones(size(verts,1),1)];
vertsHom = P*vertsX(:,:)';
for i=1:size(vertsHom,2)
vertsUV(i,1) = vertsHom(1,size(vertsHom,2)-i+1)/vertsHom(3,size(vertsHom,2)-i+1);
vertsUV(i,2) = vertsHom(2,size(vertsHom,2)-i+1)/vertsHom(3,size(vertsHom,2)-i+1);
end
% Display the image.
imshow(rgbImage);
hold on;
patch('Faces',faces,'Vertices',vertsUV,'FaceVertexCData',cindex,'FaceColor','interp','LineStyle', ':')
end