I am having an error in running this code. Kindly help.

1 次查看(过去 30 天)
Below is the error message received when I ran the classifier section of the code:
Error in SimpleFaceRecognition (line 39)
trainingFeatures(featureCount,:) = extractHOGFeatures(read(training(i),j));
Undefined function or variable 'trainingLabel'.
Error in SimpleFaceRecognition (line 47)
faceClassifier = fitcecoc(trainingFeatures,trainingLabel);
%%Load Image Information from ATT Face Database Directory
faceDatabase = imageSet('orl_faces','recursive');
%%Display Montage of First Face
figure;
montage(faceDatabase(1).ImageLocation);
title('Images of Single Face');
Display Query Image and Database Side-Side
personToQuery = 1;
galleryImage = read(faceDatabase(personToQuery),1);
figure;
for i=1:size(faceDatabase,2)
imageList(i) = faceDatabase(i).ImageLocation(5);
end
subplot(1,2,1);imshow(galleryImage);
subplot(1,2,2);montage(imageList);
diff = zeros(1,9);
%%Split Database into Training & Test Sets
[training,test] = partition(faceDatabase,[0.8 0.2]);
%%Extract and display Histogram of Oriented Gradient Features for single face
person = 5;
[hogFeature, visualization]= ...
extractHOGFeatures(read(training(person),1));
figure;
subplot(2,1,1);imshow(read(training(person),1));title('Input Face');
subplot(2,1,2);plot(visualization);title('HoG Feature');
%%Extract HOG Features for training set
trainingFeatures = zeros(size(training,2)*training(1).Count,4680);
featureCount = 1;
for i=1:size(training,2)
for j = 1:training(i).Count
trainingFeatures(featureCount,:) = extractHOGFeatures(read(training(i),j));
trainingLabel{featureCount} = training(i).Description;
featureCount = featureCount + 1;
end
personIndex{i} = training(i).Description;
end
%%Create 40 class classifier using fitcecoc
faceClassifier = fitcecoc(trainingFeatures,trainingLabel);
  3 个评论
Chidiebere Ike
Chidiebere Ike 2018-4-2
编辑:Chidiebere Ike 2018-4-2
Thanks so much for you response. I appreciate. I have tried correcting and re-running the codes again. I am still faced with error at this point of the code. Please guide me on this aspect. Below is thew error message:
*Subscripted assignment dimension mismatch.
Error in SimpleFaceRecognition (line 40) trainingFeatures(featureCount,:) = extractHOGFeatures(read(training(i),j));*
%% Extract HOG Features for training set
trainingFeatures = zeros(size(training,2)*training(1).Count,4680);
featureCount = 1; trainingLabel = []; for i=1:size(training,2) ** Break point
trainingLabel{featureCount} = training(i).Description;
for j = 1:training(i).Count
trainingFeatures(featureCount,:) = extractHOGFeatures(read(training(i),j));
featureCount = featureCount + 1;
end
personIndex{i} = training(i).Description;
end *** ** Break point
Geoff Hayes
Geoff Hayes 2018-4-2
Should trainingFeatures be a cell array? what are the dimensions of the object that you are assigning to this array? will the dimensions be the same for each iteration of the loop? From https://www.mathworks.com/matlabcentral/answers/93586-why-do-i-get-the-subscripted-assignment-dimension-mismatch-error-message,
This error occurs when you attempt to assign elements to an existing array, but the size of the variable you are trying to assign is not compatible with the existing array.

请先登录,再进行评论。

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by