I am having an error in running this code. Kindly help.
    3 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
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 Kommentare
  Geoff Hayes
      
      
 am 2 Apr. 2018
				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.
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

