menandro / vfs

Variational Fisheye Stereo
49 stars 18 forks source link

pointcloud with color? #7

Closed Freeecode closed 4 years ago

Freeecode commented 4 years ago

Hi menandro, Thank you for sharing the great work! I have tried to generate pointcloud with color, but the result isn't like the test.ply, which was provided by you. could you give me some suggestions?

menandro commented 4 years ago

Hi, I generate the pointcloud using this Matlab script.

On Tue, Jun 16, 2020 at 4:32 PM Houzhan Zhang notifications@github.com wrote:

Hi menandro, Thank you for sharing the great work! I have tried to generate pointcloud with color, but the result isn't like the test.ply, which was provided by you. could you give me some suggestions?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/menandro/vfs/issues/7, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADRO4VAE3UMDIHYLCYUXXSLRW4N2PANCNFSM4N7K47CQ .

Freeecode commented 4 years ago

Which Matlab script?

menandro commented 4 years ago

Maybe it didn't attach. Here's a text copy.

%% Convert disparity to depth (Kannala-Brandt model) close all clear all

%%%%%%% Change these %%%%%%%% stereoScaling = 2.0; mainfolder = 'D:\dev\c-projects\vfs\test_vfs/'; outputply = strcat(mainfolder, 'testwang.ply'); im = imread(strcat(mainfolder, 'wang1.png')); f = readFlowFile(strcat(mainfolder, 'disparity.flo')); mask = imread(strcat(mainfolder, 'mask.png')); %%%%%%%%%%%%%%%%%%%%%%%%%%%%

if stereoScaling == 2.0 im = imresize(im, 0.5); mask = imresize(mask, 0.5); end

u = f(:,:,1); v = f(:,:,2); K0 = [286.518 0 423.142; 0 286.602 393.321; 0 0 1]; D0 = [-0.00727452 0.05200624 -0.05105740 0.01108238 0]; K1 = [287.006 0 423.359; 0 287.001 391.369; 0 0 1]; D1 = [-0.00627662 0.04884995 -0.04713370 0.00949501 0]; K0 = K0/stereoScaling; D0 = D0/stereoScaling; K1 = K0; % Same because results are already calibrated D1 = D0;

R = [0.99998 0.00102451 -0.00620957; -0.00101936 0.999999 0.000833104; 0.00621042 -0.000826758 0.99998]; t = [-0.0639505; 0.000184912; -0.0000766807];

height = (800)/stereoScaling; width = (848)/stereoScaling;

u0 = repmat(1:width, height, 1); v0 = repmat((1:height)', 1, width); u1 = u0 + u; v1 = v0 + v;

xprime0 = (u0 - K0(1,3))/K0(1,1); yprime0 = (v0 - K0(2,3))/K0(2,2); xprime1 = (u1 - K1(1,3))/K1(1,1); yprime1 = (v1 - K1(2,3))/K1(2,2);

x0out = xprime0; y0out = yprime0; x1out = xprime1; y1out = yprime1;

%% Newton on theta % Newton-Raphson Method Frame 0 ru0 = sqrt(xprime0.^2 + yprime0.^2); theta0 = zeros(size(ru0)); for iter=1:5 thetad0 = theta0 + D0(1)theta0.^3 + D0(2)theta0.^5 + D0(3)*theta0.^7

% K1 = K0; % Newton-Raphson Method Frame 1 ru1 = sqrt(xprime1.^2 + yprime1.^2); theta1 = zeros(size(ru1)); for iter=1:5 thetad1 = theta1 + D1(1)theta1.^3 + D1(2)theta1.^5 + D1(3)*theta1.^7

%% Triangulation Zx = (t(1) - x1outt(3))./(x1out - x0out); Zy = (t(2) - y1outt(3))./(y1out - y0out);

%%%%%%% OUTPUTS %%%%%% Z = Zx; X = x0out.Z; Y = y0out.Z; Z(mask==0) = 0; X(mask==0) = 0; Y(mask==0) = 0; imshow(Z); %%%%%%%%%%%%%%%%%%%%%%

%% Save to PLY XX = X(mask~=0); YY = Y(mask~=0); ZZ = Z(mask~=0); ZZZ = ZZ;

imR = im; imG = im; imB = im; imRR = imR(mask~=0); imGG = imG(mask~=0); imBB = imB(mask~=0); cutoff = (ZZZ < 0) | (ZZZ>10) | (XX < -20) | (XX > 20);

imRR(cutoff) = []; imGG(cutoff) = []; imBB(cutoff) = []; color = cat(3, imRR, imGG, imBB);

XX(cutoff) = []; YY(cutoff) = []; ZZ(cutoff) = [];

ptCloud = pointCloud(cat(3, XX, YY, ZZ), 'Color', color); pcwrite(ptCloud, outputply);

On Tue, Jun 16, 2020 at 4:44 PM Houzhan Zhang notifications@github.com wrote:

Which Matlab script?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/menandro/vfs/issues/7#issuecomment-644593632, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADRO4VEW6U33ZEDB5Y4753LRW4PE7ANCNFSM4N7K47CQ .

Freeecode commented 4 years ago

OK,Thanks for you help! but I still have a question, could I used the pointcloud data without considering distortion?

menandro commented 4 years ago

What do you mean? The script reprojects the correspondences to 3D space, so the distortion is removed.

On Tue, Jun 16, 2020 at 5:38 PM Houzhan Zhang notifications@github.com wrote:

OK,Thanks for you help! but I still have a question, could I used the pointcloud data without considering distortion?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/menandro/vfs/issues/7#issuecomment-644622319, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADRO4VFTY243PTSVE775WGLRW4VSFANCNFSM4N7K47CQ .

Freeecode commented 4 years ago

OK!Thank you!