error while evaluating uicontrol call back

2 vues (au cours des 30 derniers jours)
vidhya sagar
vidhya sagar le 6 Mar 2019
Commenté : Geoff Hayes le 7 Mar 2019
function main_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to main (see VARARGIN)
% Choose default command line output for main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = main_OutputFcn(~, ~, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, ~, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global fname;
FileName = imread('1.jpg');
img=imread(FileName);
axes(handles.axes1);
imshow(img);
fname=FileName;
handles.filename=FileName;
guidata(hObject,handles)
img=imread(strcat('D/',fname));
axes(handles.axes2);
imshow(img);
fname=FileName;
handles.filename=FileName;
guidata(hObject,handles)
  2 commentaires
Adam
Adam le 6 Mar 2019
Modifié(e) : Adam le 6 Mar 2019
Just posting a load of code is not much help if you don't ask a question. If you have an error post the complete error message, indicating which line it refers to.
vidhya sagar
vidhya sagar le 6 Mar 2019
hi
i got error saying that " error while evaluating ui callback"
when i clickbutton i should actually be able to input 2d image which later will be converted to a 3d image. but it is showing this error.if u clear that error it will be very helpful in my project. i think function pushbutton 1 callback is causing the problem..so plzzz help

Connectez-vous pour commenter.

Réponse acceptée

Geoff Hayes
Geoff Hayes le 7 Mar 2019
vidhya - your pushbutton1 callback has the following two lines of code
FileName = imread('1.jpg');
img=imread(FileName);
One problem may be that MATLAB cannot find the 1.jpg file (you may want to provide the full path to this file). Even if this does work what is actually happening with
FileName = imread('1.jpg');
You are attempting to read an image file named 1.jpg and are storing the result into a variable that is incorrectly FileName. This isn't a file name but an image! And so then on the next line of code
img=imread(FileName);
you are passing a matrix (image) into the imread function.This could be the source of the error. These two lines should just be reduced to
img = imread('1.jpg'); % better yet - provide the full path to the file
Also, remove the global variable. You don't need this especially as you are already using the handles structure to store FileName (or perhaps you want to store the image?).
This line
img=imread(strcat('D/',fname));
will also fail unless fname is actually a file name...And rather than using strcat use fullfile.
  2 commentaires
vidhya sagar
vidhya sagar le 7 Mar 2019
sir,thanks for your help..now the image is actually getting inserted. sir i am going to provide my complete code.will u plzz help me in solving other errors..the same error "error while evaluating uicallback" is showing for button 2..plzz help me in solving this problem.
% --- Executes just before main is made visible.
function main_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to main (see VARARGIN)
% Choose default command line output for main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = main_OutputFcn(~, ~, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, ~, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global fname;
FileName = imread('1.jpg');
img=imread('1.jpg');
axes(handles.axes1);
imshow(img);
fname=FileName;
handles.filename=FileName;
guidata(hObject,handles)
img=imread(strcat('D/',fname));
axes(handles.axes2);
imshow(img);
fname=FileName;
handles.filename=FileName;
guidata(hObject,handles)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(~, ~, ~)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
warning off;
global fname;
%% Procedure for RHS
fid=fopen('fname.txt','w');
fprintf(fid,'%s',fname);
fclose(fid);
test
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(~, ~, ~)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Example 2, Corresponding points
% Load images
%global fname;
fid=fopen('fname.txt','r');
fname=fgets(fid);
fclose(fid);
I1=imread(fname);
I2=imread(strcat('D/',fname));
% Get the Key Points
Options.upright=true;
Options.tresh=0.0001;
Ipts1=OpenSurf(I1,Options);
Ipts2=OpenSurf(I2,Options);
% Put the landmark descriptors in a matrix
D1 = reshape([Ipts1.descriptor],64,[]);
D2 = reshape([Ipts2.descriptor],64,[]);
% Find the best matches
err=zeros(1,length(Ipts1));
cor1=1:length(Ipts1);
cor2=zeros(1,length(Ipts1));
for i=1:length(Ipts1)
distance=sum((D2-repmat(D1(:,i),[1 length(Ipts2)])).^2,1);
[err(i),cor2(i)]=min(distance);
end
% Sort matches on vector distance
[~, ind]=sort(err);
cor1=cor1(ind);
cor2=cor2(ind);
% Show both images
I = zeros([size(I1,1) size(I1,2)*2 size(I1,3)]);
I(:,1:size(I1,2),:)=I1; I(:,size(I1,2)+1:size(I1,2)+size(I2,2),:)=I2;
figure, imshow(I/255); hold on;
% Show the best matches
for i=1:30
c=rand(1,3);
plot([Ipts1(cor1(i)).x Ipts2(cor2(i)).x+size(I1,2)],[Ipts1(cor1(i)).y Ipts2(cor2(i)).y],'-','Color',c)
plot([Ipts1(cor1(i)).x Ipts2(cor2(i)).x+size(I1,2)],[Ipts1(cor1(i)).y Ipts2(cor2(i)).y],'o','Color',c)
end
%%%%%%%%%%%%%%%%%%%%%%%%%
q=I1;
p=I2;
%[R,T] = icp(q,p,10);
%%%%%%%%%%%%%%%%%%%%%%%%%
m = 80; % width of grid
n = m^2; % number of points
[X,Y] = meshgrid(linspace(-2,2,m), linspace(-2,2,m));
X = reshape(X,1,[]);
Y = reshape(Y,1,[]);
Z = sin(X).*cos(Y);
% Create the data point-matrix
D = [X; Y; Z];
% Translation values (a.u.):
Tx = 0.5;
Ty = -0.3;
Tz = 0.2;
% Translation vector
T = [Tx; Ty; Tz];
% Rotation values (rad.):
rx = 0.3;
ry = -0.2;
rz = 0.05;
Rx = [1 0 0;
0 cos(rx) -sin(rx);
0 sin(rx) cos(rx)];
Ry = [cos(ry) 0 sin(ry);
0 1 0;
-sin(ry) 0 cos(ry)];
Rz = [cos(rz) -sin(rz) 0;
sin(rz) cos(rz) 0;
0 0 1];
% Rotation matrix
R = Rx*Ry*Rz;
% Transform data-matrix plus noise into model-matrix
M = R * D + repmat(T, 1, n);
% Add noise to model and data
rng(2912673);
M = M + 0.01*randn(3,n);
D = D + 0.01*randn(3,n);
%% Run ICP (standard settings)
[Ricp, Ticp, ER, t] = icp(M, D, 15);
% Transform data-matrix using ICP result
Dicp = Ricp * D + repmat(Ticp, 1, n);
% Plot model points blue and transformed points red
figure;
subplot(2,2,1);
plot3(M(1,:),M(2,:),M(3,:),'bo',D(1,:),D(2,:),D(3,:),'r.');
axis equal;
xlabel('x'); ylabel('y'); zlabel('z');
title('Red: z=sin(x)*cos(y), blue: transformed point cloud');
% Plot the results
subplot(2,2,2);
plot3(M(1,:),M(2,:),M(3,:),'bo',Dicp(1,:),Dicp(2,:),Dicp(3,:),'r.');
axis equal;
xlabel('x'); ylabel('y'); zlabel('z');
title('ICP result');
% Plot RMS curve
subplot(2,2,[3 4]);
plot(0:15,ER,'--x');
xlabel('iteration#');
ylabel('d_{RMS}');
legend('bruteForce matching');
title(['Total elapsed time: ' num2str(t(end),2) ' s']);
%% Run ICP (fast kDtree matching and extrapolation)
[Ricp, Ticp, ER, t] = icp(M, D, 15, 'Matching', 'kDtree', 'Extrapolation', true);
% Transform data-matrix using ICP result
Dicp = Ricp * D + repmat(Ticp, 1, n);
% Plot model points blue and transformed points red
figure;
subplot(2,2,1);
plot3(M(1,:),M(2,:),M(3,:),'bo',D(1,:),D(2,:),D(3,:),'r.');
axis equal;
xlabel('x'); ylabel('y'); zlabel('z');
title('Red: z=sin(x)*cos(y), blue: transformed point cloud');
% Plot the results
subplot(2,2,2);
plot3(M(1,:),M(2,:),M(3,:),'bo',Dicp(1,:),Dicp(2,:),Dicp(3,:),'r.');
axis equal;
xlabel('x'); ylabel('y'); zlabel('z');
title('ICP result');
% Plot RMS curve
subplot(2,2,[3 4]);
plot(0:15,ER,'--x');
xlabel('iteration#');
ylabel('d_{RMS}');
legend('kDtree matching and extrapolation');
title(['Total elapsed time: ' num2str(t(end),2) ' s']);
%% Run ICP (partial data)
% Partial model point cloud
Mp = M(:,Y>=0);
% Boundary of partial model point cloud
b = (abs(X(Y>=0)) == 2) | (Y(Y>=0) == min(Y(Y>=0))) | (Y(Y>=0) == max(Y(Y>=0)));
bound = find(b);
% Partial data point cloud
Dp = D(:,X>=0);
[Ricp, Ticp, ER, t] = icp(Mp, Dp, 50, 'EdgeRejection', true, 'Boundary', bound, 'Matching', 'kDtree');
% Transform data-matrix using ICP result
Dicp = Ricp * Dp + repmat(Ticp, 1, size(Dp,2));
% Plot model points blue and transformed points red
figure;
subplot(2,2,1);
plot3(Mp(1,not(b)),Mp(2,not(b)),Mp(3,not(b)),'bo',...
Mp(1,b),Mp(2,b),Mp(3,b),'go',...
Dp(1,:),Dp(2,:),Dp(3,:),'r.')
axis equal;
xlabel('x'); ylabel('y'); zlabel('z');
title('Red: z=sin(x)*cos(y), blue: transformed point cloud');
% Plot the results
subplot(2,2,2);
plot3(Mp(1,not(b)),Mp(2,not(b)),Mp(3,not(b)),'bo',...
Mp(1,b),Mp(2,b),Mp(3,b),'go',...
Dicp(1,:),Dicp(2,:),Dicp(3,:),'r.');
axis equal;
xlabel('x'); ylabel('y'); zlabel('z');
title('ICP result');
% Plot RMS curve
subplot(2,2,[3 4]);
plot(0:50,ER,'--x');
xlabel('iteration#');
ylabel('d_{RMS}');
legend('partial overlap');
title(['Total elapsed time: ' num2str(t(end),2) ' s']);
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(~, ~, ~)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fid=fopen('fname.txt','r');
fname=fgets(fid);
fclose(fid);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
binarizedimage320x240=im2bw(imresize(imread(fname),[320 240]));
%imshow(binarizedimage320x240); % Binary 320x240 image
rightPoints=hough(binarizedimage320x240); % show rightPoint (x,y) coordinates from Hough Transform lines
sizeRt = size(rightPoints, 1);
x = zeros(sizeRt, 1);
y = zeros(sizeRt, 1);
for k = 1:sizeRt
x(k) = rightPoints(k,1);
y(k) = rightPoints(k,2);
end
x; % show x values
y; % show y values
% Linear fitting
%p = polyfitn(x,y,'constant x+y') % show p
%xi = 1:2:300;
%yi = polyvaln(p, xi);
%plot(x, y, 'ro', xi, yi, 'b-', 'LineWidth', 3);
%%%%%%%%%%%%%%%%%%%%%%%%%%
str = fname; % Image name in quotes;
image1 = imread(str);
image2 = image1;
%close all;
m=50; % High value implies high Depth
chngd1 = padarray(image1,[0 m],'pre');
chngd2 = padarray(image2,[0 m],'post');
chngd1(:,:,2) = 0;
chngd1(:,:,3) = 0;
chngd2(:,:,1) = 0;
result = chngd1+chngd2;
updated = result(:,m+1:length(result)-m,:);
imwrite(updated,['3D_' str]);
imshow(['3D_' str]);
title('3D image');
Geoff Hayes
Geoff Hayes le 7 Mar 2019
that's a lot of code...
In your pushbutton1 callback, why are you still doing
FileName = imread('1.jpg');
img=imread('1.jpg');
FileName is an inappropriately named variable for the image. Why read the image twice? For what purpose? And then you assign this to the global variable fname. Why do this? This isn't a file name. And you have the handles structure that you are already assigning this image too. Don't duplicate and don't use global variables.
Now in your pushbutton2 callback, you do
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(~, ~, ~)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
warning off;
global fname;
%% Procedure for RHS
fid=fopen('fname.txt','w');
fprintf(fid,'%s',fname);
fclose(fid);
test
Look what you are writing to file:
fprintf(fid,'%s',fname);
fname is an image (matrix)...it isn't a string. So that is probably the source of the error. There is also a call to test. What is this? That will throw an error too...

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by