5.000000 0.000000 10.000000
0.000000 10.000000 0.000000
10.000000 0.000000 34.000000
I have the above matrix XTX of order degreea*degreea.I am trying to compute cholesky factorization of this matrix usind dpotrf_
dpotrf_(&transc,°reea,XTX,°reea,&info); where info =0 and transc='L'
but i am getting a wrong answer.
2.236068 0.000000 4.472136
0.000000 3.162278 0.000000
10.000000 0.000000 3.741657
Can someone explain?
I want to use Matlab to replace every floating point number in a text file with another number. (let's say half the original value)
Other data (integer and string) should not change.
A few lines of my text file (each variable is in a new line):
VERTEX
8
0
10
0.000000
20
110.500000
42
0.000000
0
VERTEX
8
0
10
0.000000
20
0.000000
42
0.000000
0
VERTEX
8
0
10
124.000000
20
0.000000
42
0.000000
0
VERTEX
8
0
10
248.000000
20
0.000000
42
0.000000
0
VERTEX
8
0
10
248.000000
20
110.500000
42
0.000000
0
VERTEX
8
0
10
248.000000
20
221.000000
42
0.000000
0
Any help is appreciated.
Here is a solution using fgetl and regexp
rid = fopen('test.txt','r');
wid = fopen('test2.txt','w');
while ~feof(rid)
s = fgetl(rid); % read a line
if regexp(s, '\d+\.\d+') % float founded
fprintf(wid, '42\n'); % wite "another integer"
else
fprintf(wid, '%s\n', s); % write original data
end
end
fclose(rid);
fclose(wid);
I'm trying to calibrate iPhone camera using chessboard in OpenCV. I took 10 pictures of the chessboard for each camera with different angles and position and get corners with findChessboardCorners
cornerSubPix
Corners were detected correctly and I run calibrateCamera. Which returned 1.61 and 1.91 for each camera respectfully.
This is camera matrix and distCoefficients for the first camera:
3 3
1908.264124 0.000000 731.907383
0.000000 1905.905573 1056.741746
0.000000 0.000000 1.000000
5
0.085256 -0.224177 -0.003808 -0.011916 0.225885
This is camera matrix and distCoefficients for the second camera:
3 3
1887.450093 0.000000 729.742424
0.000000 1883.005955 1066.861173
0.000000 0.000000 1.000000
5
0.067340 -0.106684 -0.002520 -0.013685 0.096439
iPhones are absolutely the same, so I guess the intrinsic parameters also should be the same. But distortion parameters could vary from device to device. Is it normal that camera matrices are so different.
Moreoever. I repeated the experiment with different images and same camera and tis is what I got:
Returned values are 3.08 and 2.96 respectively.
This is camera matrix and distCoefficients for the first camera:
3 3
1874.278119 0.000000 773.259310
0.000000 1875.865618 1076.424783
0.000000 0.000000 1.000000
5
0.123774 -0.919622 0.000288 -0.013419 0.945573
This is camera matrix and distCoefficients for the second camera:
3 3
1942.557567 0.000000 751.467965
0.000000 1946.888384 1094.068254
0.000000 0.000000 1.000000
5
0.155755 -1.063302 0.008551 -0.014473 1.079105
Is this error acceptable? Is it what I should expect normally?
I want to rotate and align a 3d mesh model represented in face-vertex form. Transformation of a 3d matrix would have worked if my model was a in point cloud form. I couldn't find a function to convert a face-vertex information to [x y z] point cloud information.
view(-[0 20]);
the above command help to see the image in desired angle but it is not changing the face-vertex values.
My 3d object is in .stl format and i used ftread.m function to load it to matlab .
Function to read .stl file
function [fout, vout, cout] = ftread(filename)
% Reads CAD STL ASCII files, which most CAD programs can export.
% Used to create Matlab patches of CAD 3D data.
% Returns a vertex list and face list, for Matlab patch command.
%
% filename = 'hook.stl'; % Example file.
%
fid=fopen(filename, 'r'); %Open the file, assumes STL ASCII format.
if fid == -1
error('File could not be opened, check name or path.')
end
%
% Render files take the form:
%
%solid BLOCK
% color 1.000 1.000 1.000
% facet
% normal 0.000000e+00 0.000000e+00 -1.000000e+00
% normal 0.000000e+00 0.000000e+00 -1.000000e+00
% normal 0.000000e+00 0.000000e+00 -1.000000e+00
% outer loop
% vertex 5.000000e-01 -5.000000e-01 -5.000000e-01
% vertex -5.000000e-01 -5.000000e-01 -5.000000e-01
% vertex -5.000000e-01 5.000000e-01 -5.000000e-01
% endloop
% endfacet
%
% The first line is object name, then comes multiple facet and vertex lines.
% A color specifier is next, followed by those faces of that color, until
% next color line.
%
CAD_object_name = sscanf(fgetl(fid), '%*s %s'); %CAD object name, if needed.
% %Some STLs have it, some don't.
vnum=0; %Vertex number counter.
report_num=0; %Report the status as we go.
VColor = 0;
%
while feof(fid) == 0 % test for end of file, if not then do stuff
tline = fgetl(fid); % reads a line of data from file.
fword = sscanf(tline, '%s '); % make the line a character string
% Check for color
if strncmpi(fword, 'c',1) == 1; % Checking if a "C"olor line, as "C" is 1st char.
VColor = sscanf(tline, '%*s %f %f %f'); % & if a C, get the RGB color data of the face.
end % Keep this color, until the next color is used.
if strncmpi(fword, 'v',1) == 1; % Checking if a "V"ertex line, as "V" is 1st char.
vnum = vnum + 1; % If a V we count the # of V's
report_num = report_num + 1; % Report a counter, so long files show status
if report_num > 249;
disp(sprintf('Reading vertix num: %d.',vnum));
report_num = 0;
end
v(:,vnum) = sscanf(tline, '%*s %f %f %f'); % & if a V, get the XYZ data of it.
c(:,vnum) = VColor; % A color for each vertex, which will color the faces.
end % we "*s" skip the name "color" and get the data.
end
% Build face list; The vertices are in order, so just number them.
%
fnum = vnum/3; %Number of faces, vnum is number of vertices. STL is triangles.
flist = 1:vnum; %Face list of vertices, all in order.
F = reshape(flist, 3,fnum); %Make a "3 by fnum" matrix of face list data.
%
% Return the faces and vertexs.
%
fout = F'; %Orients the array for direct use in patch.
vout = v'; % "
cout = c';
%
fclose(fid);
Let's try to read a simple STL file, apply a transformation to its vertices (for example a rotation around the Z axis), and render it.
Here is an example (text format) STL file for a cube with faces perpendicular to the coordinate axes:
solid
facet normal 0.000000 1.000000 0.000000
outer loop
vertex 1.000000 1.000000 1.000000
vertex 1.000000 1.000000 -1.000000
vertex -1.000000 1.000000 -1.000000
endloop
endfacet
facet normal 0.000000 1.000000 0.000000
outer loop
vertex 1.000000 1.000000 1.000000
vertex -1.000000 1.000000 -1.000000
vertex -1.000000 1.000000 1.000000
endloop
endfacet
facet normal 0.000000 0.000000 1.000000
outer loop
vertex 1.000000 1.000000 1.000000
vertex -1.000000 1.000000 1.000000
vertex -1.000000 -1.000000 1.000000
endloop
endfacet
facet normal 0.000000 0.000000 1.000000
outer loop
vertex 1.000000 1.000000 1.000000
vertex -1.000000 -1.000000 1.000000
vertex 1.000000 -1.000000 1.000000
endloop
endfacet
facet normal 1.000000 0.000000 0.000000
outer loop
vertex 1.000000 1.000000 1.000000
vertex 1.000000 -1.000000 1.000000
vertex 1.000000 -1.000000 -1.000000
endloop
endfacet
facet normal 1.000000 0.000000 0.000000
outer loop
vertex 1.000000 1.000000 1.000000
vertex 1.000000 -1.000000 -1.000000
vertex 1.000000 1.000000 -1.000000
endloop
endfacet
facet normal 0.000000 0.000000 -1.000000
outer loop
vertex -1.000000 -1.000000 -1.000000
vertex 1.000000 1.000000 -1.000000
vertex 1.000000 -1.000000 -1.000000
endloop
endfacet
facet normal 0.000000 -1.000000 0.000000
outer loop
vertex -1.000000 -1.000000 -1.000000
vertex 1.000000 -1.000000 -1.000000
vertex 1.000000 -1.000000 1.000000
endloop
endfacet
facet normal 0.000000 -1.000000 0.000000
outer loop
vertex -1.000000 -1.000000 -1.000000
vertex 1.000000 -1.000000 1.000000
vertex -1.000000 -1.000000 1.000000
endloop
endfacet
facet normal -1.000000 0.000000 0.000000
outer loop
vertex -1.000000 -1.000000 -1.000000
vertex -1.000000 -1.000000 1.000000
vertex -1.000000 1.000000 1.000000
endloop
endfacet
facet normal -1.000000 0.000000 0.000000
outer loop
vertex -1.000000 -1.000000 -1.000000
vertex -1.000000 1.000000 1.000000
vertex -1.000000 1.000000 -1.000000
endloop
endfacet
facet normal 0.000000 0.000000 -1.000000
outer loop
vertex -1.000000 -1.000000 -1.000000
vertex -1.000000 1.000000 -1.000000
vertex 1.000000 1.000000 -1.000000
endloop
endfacet
endsolid
Save it to cube.stl. Then import it using your ftread code:
[F, V, C] = ftread('cube.stl');
I'll be ignoring the color information in C here.
This is the 3D rotation matrix that rotates 60 degrees around the Z-axis:
Rz = [ cos(pi/3), sin(pi/3), 0 ;
-sin(pi/3), cos(pi/3), 0 ;
0, 0, 1 ];
Transform all vertices:
V = V * Rz';
Draw the cube as a set of faces using MATLAB's patch command:
patch('Faces', F, 'Vertices', V, 'FaceVertexCData', (1:12)', 'FaceColor', 'flat');
view(3)
axis equal
It looks like this:
I've a simple cube which i have imported from Blender 3D; this cube has 3 different materials for its face; yellow, pink and blue.
So far i have managed to apply one material on an opengl es cube. However i am wondering how to apply several materials to the same cube.
As you will see from the OBJ file; the materials share the same vertices; only their indices change.
First thought has been to use a drawelement for each of this material; but is it first really working ? and how performance costly is it and is there a better approach in Openg GL ES 1.1 ?
Many thanks for any pointer you can provide me.
Cheers,
Stéphane
# Blender v2.61 (sub 0) OBJ File: ''
# www.blender.org
mtllib MultiColorCube.mtl
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 1.000000 1.000000
v 0.999999 1.000000 1.000001
v -1.000000 -1.000000 1.000000
v 1.000000 -1.000000 1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 1.000000 1.000000
v 1.000000 1.000000 -0.999999
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v 1.000000 -1.000000 1.000000
vn 0.000000 -1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn -1.000000 -0.000000 -0.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 0.000000 0.999969
vn 1.000000 0.000000 0.000000
usemtl bleu
s off
f 1//1 2//1 3//1 4//1
f 5//2 8//2 7//2 6//2
f 17//3 20//3 19//3 16//3
f 21//4 14//4 15//4 18//4
usemtl Jaune
s 1
f 10//5 9//5 11//6
f 12//5 10//5 11//6
usemtl Pink
s off
f 13//7 22//7 23//7 24//7
Yes, it is possible to change material state settings in between the glDrawElements calls.
You can just set color for first chunk of indices, then call glDrawElements with these indices, then set next color and so on.
Performancewise it is usually best to draw geometry in as large chunks as possible and change material settings as rarely as possible. So, assuming all you change is the color, then having colors as vertex attributes may be better, eventhough it uses up more memory for the vertex buffer. But as long as your material change is nothing more than a glColor call, you should be fine. For more detailed performance advices you need to describe in more detail what you're actually rendering.