我正在使用svm
中的matlab
处理我的遗弃物体检测项目,我完全不熟悉它。
我一直遇到这样的错误,如下所示:
Error using svmtrain (line 254)
Y and TRAINING must have the same number of rows.
Error in NewSVM (line 35)
SVMStruct = svmtrain(Data,class);
我的代码:
imageOne = imread('D:\project\PlaneBackgound.jpg'); //Read a white image
[r,c] = size(imageOne);
imageTwo = imread('D:\d backup\my movie\sankalp 2014\IMG_6984.JPG'); //Read reference image
resize = imresize(imageTwo,[r c/3]);//resize the image
K = imsubtract(imageOne,resize);
imshow(K);
imageTwo = rgb2gray(imageTwo);
imageTwo = resize(imageTwo,[200 200]);
readImages = dir('E:\Matlab\bin\data set\*.jpg'); //Read all the data from data set
for i = 1 : length(readImages) // read all the required images for providing to the svm, currently using only two images
filename = strcat('E:\Matlab\bin\data set\',readImages(i).name);
imageRead{i} = imread(filename);
end
for i = 1:2 // using for loop, trying to convert all the images read into gray scale image and modifying the size and shape.
currentimage = imageRead{i};
images{i} = currentimage;
images{i} = im2double(images{i});
images{i} = imresize(images{i},[200 200]);
images{i} = rgb2gray(images{i});
images{i} = reshape(images{i}', 1, size(images{i},1)*size(images{i},2));
end
d = size(images);
for ii=1:d
trainData(ii,:) = images(ii);
end
class = [1 -1];
Data = str2double(trainData);
SVMStruct = svmtrain(Data,class); // Here is where i get an error and cannot proceed any further beyond this
imageTwo = imresize(imageTwo, [200 200]);
imageTwo = reshape (imageTwo, 1, size(imageTwo,1)*size(imageTwo,2));
result = svmclassify(SVMStruct,imageTwo);