Error using get ......Invalid handle???!!!!!
Mostra commenti meno recenti
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
Risposte (2)
Image Analyst
il 10 Mag 2015
0 voti
Never use "clear all;" inside a callback function. It will blow away your handles structure so that you can no longer access it.
12 Commenti
Nour Mawla
il 10 Mag 2015
Walter Roberson
il 10 Mag 2015
It is pretty much the case that you should never be using "clear all" inside a script or function; that if you ever need it, use it only at the MATLAB command line.
Image Analyst
il 10 Mag 2015
I know some people disagree with me but I find it can be useful in the case where a beginner is working on a single script . All too often I've seen where the user will change a name of a variable, but not everywhere in the script, and when the script runs again it uses the old value and the user is totally confused and posts here that the variable is magically getting weird values. A clear prevents this common problem (which has even tripped me up on occasion).
Of course if you're working on multiple scripts at the same time (which I personally would not recommend especially for beginners), then a clear in one script would blow away variables in the other script. I don't think beginners have two scripts going at a time where they need to keep variables from script1 in the base workspace while they start running script2, so this will not be a common drawback.
Of course if the user transfers that script into a callback function then they will need to remove the clear. And actually we see posts asking about this situation also (where they forgot to remove the clear).
Walter Roberson
il 10 Mag 2015
Instead of teaching them "clear all", teach them to add
function MyFileName
at the beginning, where MyFileName refers to the name of the .m file. No more problem with hanging values ;-)
Image Analyst
il 10 Mag 2015
Well yeah, but then you have the people complaining that their variables are no longer visible in the workspace after they run their script. Of course they could set a breakpoint on the last line. I guess it's just a matter of style and how you like to operate.
Nour Mawla
il 11 Mag 2015
Image Analyst
il 11 Mag 2015
Please attach your latest script with the paper clip icon.
Nour Mawla
il 11 Mag 2015
Image Analyst
il 11 Mag 2015
I meant attach the whole m-file, not just 2 lines. Also, you didn't say what the error was. That looks like it should have worked.
Nour Mawla
il 11 Mag 2015
Image Analyst
il 11 Mag 2015
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
il 10 Mag 2015
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 Commenti
Nour Mawla
il 10 Mag 2015
Modificato: Walter Roberson
il 10 Mag 2015
Walter Roberson
il 10 Mag 2015
q(n) = Letters(n).n;
But first you need to describe what you wanted
get(handles.Y,'n');
to mean. What value are you trying to recall from the original data?
Nour Mawla
il 11 Mag 2015
Modificato: Walter Roberson
il 11 Mag 2015
Image Analyst
il 11 Mag 2015
There's something you're not telling/showing us. As long as "i" is different, then you're assigning a cell to the first row, i'th column of Letters. Why do you say that it's not saving? If you do this:
grayImage = Letters{1, 35};
imshow(grayImage, []);
are you saying that it does not display image #35? It displays image #50 instead?
Nour Mawla
il 11 Mag 2015
Modificato: Walter Roberson
il 11 Mag 2015
Nour Mawla
il 11 Mag 2015
Modificato: Walter Roberson
il 11 Mag 2015
Walter Roberson
il 11 Mag 2015
Value{i} = mat2cell(letter,2048,[1536 1536 ] );
Adam
il 11 Mag 2015
It is only saving a50 and b50 because you are overwriting letter and the Value that you calculate from it every time in a loop so by the end of the loop you only have the last ones left.
You need to store all your values in an array e.g.
Value{i} = mat2cell(letter,2048,[1536 1536 ] );
then you will have them all still after your loop ends.
Nour Mawla
il 11 Mag 2015
Walter Roberson
il 11 Mag 2015
Value(i) = mat2cell(letter,2048,[1536 1536]);
Adam
il 11 Mag 2015
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!
Categorie
Scopri di più su Interactive Control and Callbacks in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





