11/11/2015

Get Rotation and Translation from 2 groups of 3d points (calculate R, T between 2 points.)

I made this example source code referencing from this site.
http://nghiaho.com/?page_id=671


Key idea(main processing) is using SVD(singular Value Decomposition)

I  made first group consist of 3d points by random selection.



Second groups of 3d points is made by random rotation and translation.
Blue color is points of second group.


How to find R,T between 2 groups of 3d points ?
for detail, see below matlab source code.
After get R,T, second group can transform to original position.



matlab source code.

printf

%Get R,T from 2 groups of 3d points

%The first group is created by random selection
A3pt = rand(3, 10);
figure(10);
plot3(A3pt(1,:),A3pt(2,:),A3pt(3,:),'r.');%, axis equal

%The second group is made by random R,T from first group
v1=0.6*(2*rand-1); 
v2=0.6*(2*rand-1); 
v3=0.6*(2*rand-1);
R1=[1 0 0;0 cos(v1) -sin(v1);0 sin(v1) cos(v1)];
R2=[cos(v2) 0 sin(v2);0 1 0;-sin(v2) 0 cos(v2)];
R3=[cos(v3) -sin(v3) 0;sin(v3) cos(v3) 0;0 0 1];
R=R3*R2*R1;
T = rand(3,1);

B3pt = R*A3pt; %Rotation
for i=1:3 %dimension
        B3pt(i,:)=B3pt(i,:)+T(i);      % translation
end

%show 2 group
figure(1);
plot3(A3pt(1,:),A3pt(2,:),A3pt(3,:),'r.',B3pt(1,:),B3pt(2,:),B3pt(3,:),'bo');%, axis equal

%% get R,T
MeanA = mean(A3pt, 2);
MeanB = mean(B3pt, 2);

HH=zeros(3,3);
n = length(A3pt);
for i=1:n
    tA = A3pt(:,i) - MeanA;
    tB = B3pt(:,i) - MeanB;
    hh = tB * tA';
    HH = HH + hh;
end

[U,~,V]=svd(HH); 
Ri=V*U'; %get R
Ti=MeanA-Ri*MeanB; %Get T


%% confirm

B3pt_=Ri*B3pt;                       % Rotation 시키기 Apply transformation
for i=1:3 %dimension
    B3pt_(i,:)=B3pt_(i,:)+Ti(i);      % translation 시키기
end

%show 2 group
figure(2);
plot3(A3pt(1,:),A3pt(2,:),A3pt(3,:),'r.',B3pt_(1,:),B3pt_(2,:),B3pt_(3,:),'bo');%, axis equal


    
    
    



...

11/09/2015

integer to string ( _itoa_s )

see code


...
int increase = 0;
char str[100];
_itoa_s(time(0),str,10); //10 means decimal so 8:octal, 16Lhex, 2:binary
sprintf_s(str, "%s_%d", str, increase);
printf("%s \n", str );


...

2 rect intersection, union and overlap ratio in opencv Rect

using & and | operator and area() method.

see code


..
Rect A(100, 100, 100, 100); //x, y, width, hegiht
Rect B(80, 80, 100, 100); //x, y, width, hegiht

printf("intersection area= %d\n", (A&B).area());
printf("union area = %d\n", (A|B).area());
printf("instersection ratio %lf \n", (A&B).area() / float( (A | B).area() ));


..



11/08/2015

long delay opencv gpu/cuda/GpuMat

When using opencv GpuMat, there is a long delay in a use of the first line code.


In this page,
http://answers.opencv.org/question/52304/long-delay-on-cvgpugpumatupload-after-upgrade-to-gtx970/
There is solution in article.

In one word.



Add 5.2 option in CUDA_ARCH_BIN table when cmake setting.
In my case, this delay problem cleared, after build by set this option.

Thank you.