Error using get ......Invalid handle???!!!!!
2 次查看(过去 30 天)
显示 更早的评论
Good after noon everyone
I'm trying to build a GUI that would match an input image and a database of images...I'm using the edge function
but when calling the database I get the following error
Error using get
Invalid handle
That's the function of the button that calls the database
function source_Callback(hObject, eventdata, handles)
load Letters
global Letters;
num=size(Letters,2);
q = zeros (1:num);
for n=1:num
handles.Y=Letters{1,n};
q(n) = get(handles.Y,'n');
guidata(hObject,handles);
end
handles.output = hObject;
Thats the comparing function
load Letters
global Letters;
num=size(Letters,2);
matched = 0;
k = handles.XX;
k = rgb2gray(k);
edge_k= edge(k,'prewitt',[]);
display('testing');
for n=1:num
p = handles.Y;
edge_p = edge(p,'prewitt',[]);
for i = 1:1:400
for j = 1:1:400
if(edge_p(i,j))==1&&(edge_k(i,j)==1)
matched = matched+1;
disp (matched);
end
end
end
and finally the function used in creating the database
clear all;
close all;
clc;
for i = 1:50
A = imread(strcat('Sample 2\A\a',int2str(i),'.png'));
A = rgb2gray(A);
letter=A ;
Letters(1,i)=mat2cell(letter,2048,[1536 ] );
end
save ('Letters','Letters')
Please help me correct the error
when I removed the get function when matching it displayed the same number of matched point for all 50 images
Thank you
0 个评论
回答(2 个)
Image Analyst
2015-5-10
Never use "clear all;" inside a callback function. It will blow away your handles structure so that you can no longer access it.
12 个评论
Image Analyst
2015-5-11
I'm about to give up here. You keep changing your code and don't even attach it like I requested. First you say:
Letters(1,i)=mat2cell(
then you say
Values=mat2cell(
And did you know letters and Letters are different because MATLAB is case sensitive ? Anyway, these are the two links that you need to solve all your MATLAB problems:
and
Good luck.
Walter Roberson
2015-5-10
Your call
Letters(1,i)=mat2cell(letter,2048,[1536 ] );
is going to be the same as
Letters{i} = letter;
The mat2cell() only has the effect of breaking up the matrix into smaller pieces if the following arguments include at least one non-scalar vector. When both of the values are scalar, the effect would be to give an error message if the array was not 2048 x 1536, and then to wrap the matrix inside a cell array.
Notice that what you store into Letters{i} is not an object, just a numeric matrix. As it is not an object at all, it has no property 'n' to be fetched by get().
I suspect that what you are looking for is something like,
Letters(1,i) = struct('letter', letter, 'n', n );
and then in your callback,
handles.Y = Letters(n).letter;
q(n) = letters(n).n;
11 个评论
Adam
2015-5-11
Yeah, I couldn't remember which it needed to be and didn't have time to remember how to use mat2cell to test it so I went for the wrong one!
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!