Error using reshape To RESHAPE the number of elements must not change. Error in load_database (line 17) v(:,(i-1)*​10+j)=resh​ape(a,size​(a,1)*size​(a,2),1); Error in official (line 75) number = libCheck(l​oad_databa​se(5),imre​ad('test2.​b

1 次查看(过去 30 天)
if(isempty(loaded)) v=zeros(10304,10*n); for i=1:n cd(strcat('C:\Users\123\Videos\matlabFaceRecognitionRealTime-master\matlabFaceRecognitionRealTime-master\S',num2str(i))); % disp(i); for j=1:10 disp(j) a=imread(strcat(num2str(j),'.bmp')); v(:,(i-1)*10+j)=reshape(a,size(a,1)*size(a,2),1); end cd .. end w=uint8(v); % Convert to unsigned 8 bit numbers to save memory. end %loaded=1; % Set 'loaded' to aviod loading the database again. out=w;

回答(2 个)

Walter Roberson
Walter Roberson 2016-11-9
The code expects the image to be grayscale but it is RGB

KSSV
KSSV 2016-11-9
编辑:KSSV 2016-11-9
Your a after reading the image is a 3D matrix. Say of size (m,n,3). In reshape you are using reshape(a,size(a,1)*size(a,2),1), this means you are suing only m*n numbers. Rest of the numbers (2*m*n) are missed, there fore this problem is arising. You have to see to it that a is a 2D matrix.
Either convert your image to gray or use a = a(:,:,1) ;

Community Treasure Hunt

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

Start Hunting!

Translated by