Effacer les filtres
Effacer les filtres

Error in matlab code

1 vue (au cours des 30 derniers jours)
Shravanthi le 9 Mar 2014
Hello everyone, I'm doing a project in gesture recognition of robotic arm . What it basically does is to compare the gesture which is obtained from a webcam with the other gestures which have been previously taken and stored in matlab. There are different gestures stored in matlab and classification of the input gesture is done by correlating the input gesture with the stored gestures.
The input gesture is considered to be one of the stored gestures to which maximum correlation occurs.
my code is
clc; clear all; close all;
vid = videoinput('winvideo', 1, 'YUY2_640x480'); %specify the video adaptor src = getselectedsource(vid); vid.ReturnedColorspace = 'grayscale'; %define the color format to GRAYSCALE vid.FramesPerTrigger = 5; preview(vid); %preview the video object
while(1) preview(vid); %preview the video object currentimg=getsnapshot(vid); %capture the image of interest
grayImage = currentimg;
% Get the dimensions of the image. % numberOfColorBands should be = 1. [rows, columns, numberOfColorBands] = size(grayImage);%returns array dimensions if numberOfColorBands > 1 % It's not really gray scale like we expected - it's color. % Convert it to gray scale by taking only the green channel. grayImage = grayImage(:, :, 2); % Take green channel. end
% % Let's compute and display the histogram. % [pixelCount, grayLevels] = imhist(grayImage);
% Get the gradient image to find the edges of the hand. gradientImage = imgradient(grayImage);
% Put a white line along the bottom, right, % and left side to "close off" the hand and arm.
gradientImage(:,1) = 255; % Make column 1 white. gradientImage(end,:) = 255; % Make last row white. gradientImage(:,end) = 255; % Make last column white.
binaryImage = gradientImage > 40; % Fill Holes binaryImage = imfill(binaryImage, 'holes'); % Remove tiny regions. binaryImage = bwareaopen(binaryImage, 5000);
%--------------------------------------... % Extract the largest area using our custom function ExtractNLargestBlobs(). % This is the meat of the demo! biggestBlob = ExtractNLargestBlobs(binaryImage, 1);
% Display the image.
imshow(biggestBlob, []); title('Final Image');
[labeledImage, numberOfBlobs] = bwlabel(biggestBlob, 8);
% Get all the blob properties. blobMeasurements = regionprops(labeledImage, 'BoundingBox','Area'); allBlobAreas = [blobMeasurements.Area];
% Display the original gray scale image. imshow(grayImage, []);
% Loop through all blobs, putting up Bounding Box. hold on; % Prevent boxes from blowing away the image and prior boxes. for k = 1 : numberOfBlobs boundingBox = blobMeasurements(k).BoundingBox; % Get box. x1 = boundingBox(1); y1 = boundingBox(2); x2 = x1 + boundingBox(3) - 1; y2 = y1 + boundingBox(4) - 1; verticesX = [x1 x2 x2 x1 x1]; verticesY = [y1 y1 y2 y2 y1]; plot(verticesX, verticesY);
gesture = imcrop(grayImage,blobMeasurements(k).Bou... gesture =imresize(gesture, [120,120]);
limits = stretchlim(gesture, 0.05); gesture = imadjust(gesture, limits, []);
for i=1:50
J{i}=corr2(gesture,gest1Cell{i}); L{i}=corr2(gesture,gest2Cell{i}); M{i}=corr2(gesture,gest3Cell{i}); N{i}=corr2(gesture,gest4Cell{i}); O{i}=corr2(gesture,gest5Cell{i}); P{i}=corr2(gesture,gest6Cell{i});
greatestJ=cellfun(@(a) max(a(:)),J); R = max(greatestJ(1,:));
greatestL=cellfun(@(b) max(b(:)),L); S = max(greatestL(1,:));
greatestM=cellfun(@(c) max(c(:)),M); T = max(greatestM(1,:));
greatestN=cellfun(@(d) max(d(:)),N); U = max(greatestN(1,:));
greatestO=cellfun(@(e) max(e(:)),O); V = max(greatestO(1,:));
greatestP=cellfun(@(f) max(f(:)),P); W = max(greatestP(1,:));
G= max(R,S,T,U,V,W);
if ((G==R)&&(G>0.55)) display('DROP');
elseif ((G==S)&&(G>0.55)) display('PICK');
elseif ((G==T)&&(G>0.55)) display('RIGHT');
elseif ((G==U)&&(G>0.55)) display('UP');
elseif ((G==V)&&(G>0.55)) display('LEFT');
elseif ((G==W)&&(G>0.55)) display('DOWN');
else display('NO MOTION'); end
But as i run the program , i get an error message as "Undefined function or variable 'gesture'" in the line J{i}=corr2(gesture,gest1Cell{i});
Any help would really be appreciated, thank you for your time.
  1 commentaire
Jan le 9 Mar 2014
Please format your code properly by using the "{} Code" button.

Connectez-vous pour commenter.

Réponses (2)

Jan le 9 Mar 2014
The error message is clear: The name "gesture" is not known.
You can use the debugger to step through your code line by line to find out, why this variable has not been defined.

Image Analyst
Image Analyst le 9 Mar 2014
Something looks really wrong with these lines:
gesture = imcrop(grayImage,blobMeasurements(k).Bou...
gesture =imresize(gesture, [120,120]);
What is your intent there? Why did you put a continuation sign at the end of the top line (in the middle of a word), and then not even continue it properly?
You have to understand the code you assemble from different sources. I see some of my code haphazardly pasted in there. You can't just slap together a bunch of random code from different sources and expect it to work. For one thing the variable names won't match up.


En savoir plus sur Recognition, Object Detection, and Semantic Segmentation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by