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

📄 torr_tool.m

📁 matlab三维重建程序
💻 M
📖 第 1 页 / 共 3 页
字号:
%---------------------------------------------------------------------\\\% --------------------------------------------------------------------function varargout = load_image_button_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.pushbutton5.[filename1, pathname1] = uigetfile_name('*.bmp;*.jpg;*.gif','Pick an input image')[filename2, pathname2] = uigetfile_name('*.bmp;*.jpg;*.gif','Pick a second input image')load_2images(h, eventdata, handles, varargin, filename1, pathname1,filename2, pathname2);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --------------------------------------------------------------------function varargout = clear_button_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.pushbutton6.% extracting the handle of the axes in which to display the imageax_handle2 = handles.axes2; axes(ax_handle2);set(get(ax_handle2, 'Title'), 'Visible', 'off');set(get(ax_handle2, 'Title'),'String', 'fff');hold offimage(handles.i1, 'Parent', ax_handle2,'XData',-handles.image_centrex,'YData',-handles.image_centrey);%  imshow(i1, 'Parent', ax_handle2);ax_handle3 = handles.axes3; axes(ax_handle3);hold offimage(handles.i2, 'Parent', ax_handle3,'XData',-handles.image_centrex,'YData',-handles.image_centrey);% --------------------------------------------------------------------function varargout = close_button_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.close_button.pos_size = get(handles.figure1,'Position');user_response = modaldlg([pos_size(1)+pos_size(3)/5 pos_size(2)+pos_size(4)/5]);switch user_responsecase {'no','cancel'}    % take no actioncase 'yes'    % Prepare to close GUI application window    %                  .    %                  .    %                  .    delete(handles.figure1)end% --------------------------------------------------------------------function varargout = help_button_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.help_button.HelpPath = which('stereo.htm');web(HelpPath); % --------------------------------------------------------------------function varargout = corn_param_button_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.corn_param_button.pos_size = get(handles.figure1,'Position');dlg_pos = [pos_size(1)+pos_size(3)/5 pos_size(2)+pos_size(4)/5];corn_param = torr_c_menu(handles, dlg_pos);handles.n_corners = corn_param(1);handles.corner_sigma = corn_param(2);handles.corner_width = corn_param(3);corn_param% saving the GUI dataguidata(handles.figure1, handles);%---------------------------------------------------------------------\\\function save_corners_to_file(n_corners1, n_corners2, ccr1, ccr2, FID)fprintf(FID,'%1.0f \n',n_corners1);fprintf(FID,'%1.0f \n',n_corners2);fprintf(FID,'%1.1f %1.1f \n',ccr1');fprintf(FID,'%1.1f %1.1f \n',ccr2');% --------------------------------------------------------------------function varargout = save_corner_button_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.save_corner_button.[fname,pname] = uiputfile_name('*.cor','Put Corner File');ccr1 = handles.ccr1;ccr2 = handles.ccr2;%save([pname fname], 'n_corners', 'ccr1', 'ccr2', '-ASCII')FID = fopen([pname fname],'w');n_corners1 = handles.n_corners1;n_corners2 = handles.n_corners2;save_corners_to_file(n_corners1, n_corners2, ccr1, ccr2, FID)fclose(FID);% --------------------------------------------------------------------function [n_corners1, n_corners2, ccr1, ccr2] = load_corners_from_file(FID)n_corners1 = fscanf(FID,'%f',1);n_corners2 = fscanf(FID,'%f',1);ccr1  = fscanf(FID,'%f %f',[2 n_corners1]);ccr2  = fscanf(FID,'%f %f',[2 n_corners2]);% --------------------------------------------------------------------function varargout = load_corner_button_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.load_corner_button.[fname,pname] = uigetfile_name('*.cor','Load Corner File');if isempty(fname)    returnendFID = fopen([pname fname]);[n_corners1, n_corners2, ccr1, ccr2] = load_corners_from_file(FID);handles.n_corners1 = n_corners1;handles.n_corners2 = n_corners2;handles.ccr1 = ccr1';handles.ccr2 = ccr2';fclose(FID);set(handles.save_corner_button, 'Enable', 'on');set(handles.match_button, 'Enable', 'on');set(handles.match_param_button, 'Enable', 'on');%once we have done the matches we can no longer redo corners otherwise things might be inconsistentset(handles.detect_corner_button, 'Enable', 'off');% saving the GUI dataguidata(handles.figure1, handles);clear_button_Callback(h, eventdata, handles, varargin);display_corners_in_figure(handles)%---------------------------------------------------------------------\\\% --------------------------------------------------------------------function varargout = match_button_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.match_button.%shift the x,y coordinates so we can access the image directlyccr1(:,1) = handles.ccr1(:,1) + handles.image_centrex;ccr1(:,2) = handles.ccr1(:,2) + handles.image_centrey;ccr2(:,1) = handles.ccr2(:,1) + handles.image_centrex;ccr2(:,2) = handles.ccr2(:,2) + handles.image_centrey;matches12 = torr_corn_matcher(handles.d1, handles.d2, ccr1, ccr2, handles.max_disparity,handles.match_half_size);disp('Number of matches:')length(matches12)matches12(:,1) = matches12(:,1) - handles.image_centrex;matches12(:,2) = matches12(:,2) - handles.image_centrey;matches12(:,3) = matches12(:,3) - handles.image_centrex;matches12(:,4) = matches12(:,4) - handles.image_centrey;handles.matches12 = matches12;handles.n_matches = length(matches12);set(handles.save_match_button, 'Enable', 'on');    set(handles.mapsac_button, 'Enable', 'on');set(handles.mapsac_parameters_button, 'Enable', 'on');%once we have done the matches we can no longer redo corners otherwise things might be inconsistentset(handles.detect_corner_button, 'Enable', 'off');guidata(handles.figure1, handles);display_matches(h, eventdata, handles, varargin);% --------------------------------------------------------------------function varargout = display_matches(h, eventdata, handles, varargin)% extracting the handle of the axes in which to display the imageax_handle2 = handles.axes2;ax_handle3 = handles.axes3; ccr1 = handles.ccr1;ccr2 = handles.ccr2;matches= handles.matches12;axes(ax_handle2);hold onaxes(ax_handle3);hold onx1 = matches(:,1);y1 = matches(:,2);x2 = matches(:,3);y2 = matches(:,4);u1 = x2 - x1;v1 = y2 - y1;plot (matches(:,1), matches(:,2),'r+');hold onplot (matches(:,3), matches(:,4),'r+');display_numbers = 0;if display_numbers    mat_index1 = 1:length(matches);    mat_index1 = mat_index1';    mat_index = num2str(mat_index1);    text(matches(:,1), matches(:,2),mat_index)endquiver(x1, y1, u1, v1, 0)hold off% % plot(ccr1(:,1), ccr1(:,2), 'r.')% plot(ccr2(:,1), ccr2(:,2), 'c.')% % for i = 1:length(mat12)%     if mat12(i) ~= 0%         a = [ccr1(i,1),ccr2(mat12(i),1)];  %x1 x2%         b = [ccr1(i,2),ccr2(mat12(i),2)];	%y1 y2%         %x1 y1%         %x2 y2%         line(a,b);%     end% endaxes(ax_handle2);        hold offaxes(ax_handle3);        hold off% --------------------------------------------------------------------function varargout = match_param_button_Callback(h, eventdata, handles, varargin)pos_size = get(handles.figure1,'Position');dlg_pos = [pos_size(1)+pos_size(3)/5 pos_size(2)+pos_size(4)/5];match_param = torr_m_menu(handles, dlg_pos);handles.max_disparity = match_param(1);handles.match_half_size = match_param(2);% saving the GUI dataguidata(handles.figure1, handles);%---------------------------------------------------------------------% --------------------------------------------------------------------function varargout = save_image1_button_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.save_image1_button.ax_handle2 = handles.axes2;%ax_handle3 = handles.axes3; % hf1 = figure;% %plot(sin(1:10));%hf2 = figure;%ha = findobj('Parent',hf1);% ax_handle2 = handles.axes2;% new_axes = axes(ax_handle2);% set(new_axes, 'Parent', hf1);% % [fname,pname] = uiputfile('*.fig');% saveas(ax_handle2,[pname fname ]);%hgsave(ax_handle2,[pname fname ]);new_fig = figure;new_axes = copyobj(ax_handle2,new_fig)%set(new_axes,'Position',[.5 .5 .8 .8],'DataAspectRatioMode','auto','PlotBoxAspectRatioMode','auto');%get(new_axes)axis_position = get(new_axes,'Position');set(new_axes,'Position',[10 7  axis_position(3) axis_position(4) ]);%keyboard% fff = handles.figure1;% saveas(fff,'bigfig.bmp');% --------------------------------------------------------------------function varargout = save_image2_button_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.save_image2_button.ax_handle3 = handles.axes3;% [fname,pname] = uiputfile('*.fig');% saveas(ax_handle3,[pname fname ]);%hgsave(ax_handle3,[pname fname ]);new_fig = figure;new_axes = copyobj(ax_handle3,new_fig)%set(new_axes,'Position',[.5 .5 .8 .8],'DataAspectRatioMode','auto','PlotBoxAspectRatioMode','auto');%get(new_axes)axis_position = get(new_axes,'Position');set(new_axes,'Position',[10 7  axis_position(3) axis_position(4) ]);%keyboard% --------------------------------------------------------------------function varargout = manual_match_button_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.manual_match_button.set(handles.save_match_button, 'Enable', 'on');    set(handles.load_match_button, 'Enable', 'on');matches12 = torr_add_manual_matches(handles.axes2,handles.axes3);handles.matches12 = matches12;handles.n_matches = length(matches12);%also store cornersccr1(:,1) = matches12(:,1);ccr1(:,2) = matches12(:,2);ccr2(:,1) = matches12(:,3);ccr2(:,2) = matches12(:,4);handles.ccr1 = ccr1;handles.ccr2 = ccr2;%once we have done the matches we can no longer redo corners otherwise things might be inconsistentset(handles.detect_corner_button, 'Enable', 'off');guidata(handles.figure1, handles);display_matches(h, eventdata, handles, varargin);if handles.n_matches > 7;    set(handles.mapsac_button, 'Enable', 'on');    set(handles.mapsac_parameters_button, 'Enable', 'on');    set(handles.ImproveF_button, 'Enable', 'on');end% --------------------------------------------------------------------function varargout = save_match_button_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.save_corner_button.[fname,pname] = uiputfile_name('*.matches','Put Match File');n_matches = handles.n_matches;matches12 = handles.matches12;%save([pname fname], 'n_corners', 'ccr1', 'ccr2', '-ASCII')FID = fopen([pname fname],'w');fprintf(FID,'%1.0f \n',n_matches);fprintf(FID,'%1.1f %1.1f %1.1f %1.1f  \n',matches12');%now store original corners for good measure:n_corners = handles.n_corners;ccr1 = handles.ccr1;ccr2 = handles.ccr2;n_corners1 = handles.n_corners1;n_corners2 = handles.n_corners2;save_corners_to_file(n_corners1, n_corners2, ccr1, ccr2, FID);fclose(FID);% --------------------------------------------------------------------function varargout = load_match_button_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.load_match_button.% Stub for Callback of the uicontrol handles.load_corner_button.[fname,pname] = uigetfile_name('*.matches','Load Match File');if isempty(fname)    returnendFID = fopen([pname fname]);n_matches = fscanf(FID,'%f',1)handles.n_matches = n_matches;matches12  = fscanf(FID,'%f %f %f %f',[4 n_matches]);[n_corners1, n_corners2, ccr1, ccr2] = load_corners_from_file(FID);handles.n_corners1 = n_corners1;handles.n_corners2 = n_corners2;handles.ccr1 = ccr1';handles.ccr2 = ccr2';fclose(FID);handles.matches12 = matches12';set(handles.save_corner_button, 'Enable', 'on');set(handles.save_match_button, 'Enable', 'on');set(handles.match_button, 'Enable', 'on');set(handles.match_param_button, 'Enable', 'on');% Stub for Callback of the uicontrol handles.pushbutton28.set(handles.mapsac_button, 'Enable', 'on');set(handles.mapsac_parameters_button, 'Enable', 'on');% saving the GUI dataguidata(handles.figure1, handles);clear_button_Callback(h, eventdata, handles, varargin)display_matches(h, eventdata, handles, varargin)% --------------------------------------------------------------------function varargout = display_inliers(h, eventdata, handles, varargin)% extracting the handle of the axes in which to display the imageax_handle2 = handles.axes2;ax_handle3 = handles.axes3; ccr1 = handles.ccr1;ccr2 = handles.ccr2;axes(ax_handle2);hold onaxes(ax_handle3);hold onmatches12 = handles.inlier_matches;plot(matches12(:,3),matches12(:,4),'c.');for i = 1:length(matches12)    a = [matches12(i,1),matches12(i,3)];  %x1 x2    b = [matches12(i,2),matches12(i,4)];	%y1 y2    line(a,b,'Color','g');endaxes(ax_handle2);hold onplot(matches12(:,3),matches12(:,4),'c.');%can i fix this to make this faster??for i = 1:length(matches12)    a = [matches12(i,1),matches12(i,3)];  %x1 x2    b = [matches12(i,2),matches12(i,4)];	%y1 y2    line(a,b,'Color','g');endaxes(ax_handle2);        hold offaxes(ax_handle3);        hold off%MAPSAC is the Bayesian version of MLESAC, and it is easier to pronounce!% --------------------------------------------------------------------function varargout = mapsac_button_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.mapsac_button.%run mapsac to get ff_optim_parameters = [handles.no_samp, handles.f_threshold];[f,f_sq_errors, n_inliers,inlier_index] = torr_estimateF(handles.matches12, handles.m3, f_optim_parameters, 'mapsac');disp('goodness of fit before non linear:')norm(f_sq_errors)handles.f = f;handles.inlier_matches = handles.matches12(inlier_index,:);

⌨️ 快捷键说明

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