⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 z2d3d_example.m

📁 利用matlab编程
💻 M
字号:
function[ok] = z2D3D_example()
ok = -1;
% size etc.
MarlinSizeX = 640;
MarlinSizeY = 480;
PMDChip = 2;%以下两个参数是Set_Chip中用到的,usually 2 for usb PMD, be it with or without 2D
Use2DInPMDDll = 1;%specifies whether 2D chip is to be used (1) or not (<>0)
SizeX = 64;
SizeY = 48;
sizefooter = 4;
% phase images
phases = zeros(8, 'int32');
phases(1) = 7;
phases(2) = 1;
phases(3) = 3;
phases(4) = 5;
phases(5) = 7;
phases(6) = 1;
phases(7) = 3;
phases(8) = 5;
% reserve memory
dist = zeros(SizeX, SizeY, 'double'); % for the range data
MA = zeros(SizeX, SizeY, 'double'); % for the modulation amplitude
pict = zeros(SizeX, SizeY, 'int16'); % for the 3D greyscale image
raw = zeros(1, ((SizeX*SizeY+sizefooter)*2)*4, 'int16'); % 3D image raw data
MarlinBild = zeros( MarlinSizeX, MarlinSizeY, 'uint8' ); % for the 2D greyscale image

% load DLL
if ~libisloaded('PMDDll')
    loadlibrary('C:\Programme\z2D3D\PMDDll','C:\Programme\z2D3D\PMDDll.h');
end
disp('OK: Library loaded.');

% init DLL
r = calllib('PMDDll', 'z2D3D_setChip', PMDChip, Use2DInPMDDll, 1, 4 );
if ( r < 0 )
	displaystring = strcat('FAILED: set chip failed:',num2str(r));
    errordlg(displaystring);
    unloadlibrary('PMDDll');
    return;
end

% init camera
r = calllib('PMDDll', 'z2D3D_init', 'USB0', 'C:\Programme\z2D3D\Bitfiles\default.rbt', PMDChip, Use2DInPMDDll, 20, phases, 1, 4 );
if ( r < 0)
    displaystring = strcat('FAILED: init failed:',num2str(r));
    errordlg(displaystring);
    unloadlibrary('PMDDll');
    return;
end
disp('OK: PMD camera initialized.');

% prepare for image acquisition
r = calllib('PMDDll', 'z2D3D_Prepare', 1);
if ( r<0 )
    displaystring = strcat('FAILED: preparing failed:',num2str(r));
    errordlg(displaystring);
else
    disp('Memory reserved.');
end

% trigger cycle,可以在这里设置曝光时间。
disp('preparing cycle...');
cycles = ones(4, 1, 'uint32');
if ( Use2DInPMDDll > 0 )
    cycles(1) = bin2dec('11');
end
[r cycles] = calllib('PMDDll', 'z2D3D_TriggerCycle', 4, cycles, 0);
    errordlg('FAILED: setting trigger cylce failed!');
    unloadlibrary('PMDDll');
    return;
end
disp('cycle prepared.');

% image acquisiton loop
for i = 1 : 100
    r = calllib('PMDDll', 'z2D3D_Do', 0);
    if ( r < 0 )
        displaystring = strcat('FAILED: do failed:',num2str(r));
		errordlg(displaystring);
        break;
    end

    [r dist MA pict raw MarlinBild] = calllib('PMDDll', 'z2D3D_Fetch', 0, dist, MA, pict, raw, MarlinBild);
    %All of the function that are used in Matlab must be call from libary first
    if ( r < 0 )
        displaystring = strcat('FAILED: fetch failed:',num2str(r));
		errordlg(displaystring);
        break;
    end
    
    figure(1); colormap(gray);
    
    subplot(2,2,1);
    imshow(MarlinBild);
    title( '2D greyscale image' );
	
    subplot(2,2,2);
    imagesc(pict);
    title( '3D greyscale image' );
    
    subplot(2,2,3);
    imagesc( dist );
    title('distance image');
    
    subplot(2,2,4);
    imagesc( MA );
    title('modulation amplitude image');
end

% de-initialize camera
r = calllib('PMDDll', 'z2D3D_deinit', 0);
if ( r < 0 )
	displaystring = strcat('FAILED: deinit failed:',num2str(r));
	errordlg(displaystring);
end
unloadlibrary('PMDDll');

% that's it, return
ok=0;
return;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -