Online see about using OPENCV to classify the image, this time with Matlab to do some attempts, the image data set is: Link: https://pan.baidu.com/s/1i5OhC7z Password: utn7, other MATLAB version/HTTP blog.csdn.net/libin88211/article/details/19968205, click the Open link, http://blog.csdn.net/jcy1009015337/article/details/ 53763484 additional OPENCV versions for: Click to open the link, http://blog.csdn.net/always2015/article/details/47107129
Nonsense not to say, directly on the code (for MATLAB 2016b version and above), the code has a corresponding comment.
The image I trained on disk has the following 5 categories, eliminating the previous process of making txt storage image paths:
The test image is distributed as:
Percent percent with hog feature for multi-classification of images, SVM training, 1 VS 1 percent 1 datasets, including training and testing (note your own picture storage path, appendix I to show example download Image link) Imdstrain = Imagedatastore (' f:\ Svm_images\train_images ',... ' includesubfolders ', true,... ' labelsource ', ' Foldernames '); Imdstest = Imagedatastore (' F:\svm_images\test_image ');
percent display the training of the picture type labels and the number of count Train_disp = Counteachlabel (Imdstrain);
Disp (TRAIN_DISP);
percent 2 hog feature extraction for each image in the training set, the same as the test image % preprocessing image, mainly to get features feature size, which is related to image size and hog characteristic parameters ImageSize = [256,256];% scales all images to this size Image1 = Readimage (imdstrain,1); Scaleimage = imresize (image1,imagesize); [Features, visualization] = Extracthogfeatures (scaleimage); Imshow (scaleimage); Plot (visualization) % feature extraction for all training images Numimages = length (imdstrain.files); Featurestrain = zeros (Numimages,size (features,2), ' single '); % Featurestrain for single precision for i = 1:numimages Imagetrain = ReadimAge (Imdstrain,i); Imagetrain = Imresize (imagetrain,imagesize);
Featurestrain (i,:) = Extracthogfeatures (imagetrain); End % All training image tags Trainlabels = Imdstrain.labels; % start SVM Multi-classification training, note: FITCSVM for two classification, FITCECOC for Multi-classification, 1 VS 1 method Classifer = Fitcecoc (Featurestrain, Trainlabels); percent forecast and display forecast renderings numtest = length (imdstest.files); For i = 1:numtest testimage = Readimage (imdstest,i); Scaletestimage = Imresize (testimage,imagesize); featuretest = Extracthogfeatures (scaletestimage); [predictindex,score] = predict (classifer,featuretest); Figure;imshow (testimage); title ([' Predictimage: ', char (Predictindex)]);
End
Command line pair Training set Imdstrain
The results of the statistical output are as follows:
The first image shows the extracted hog features, this can be a primary understanding of the characteristics of the selection of the appropriate, not suitable to adjust the parameters inside the extracthogfeatures, such as Cellsize,blocksize,bins, Specifically, you can refer to this click to open the link http://cn.mathworks.com/help/vision/ref/extracthogfeatures.html?searchHighlight= Extracthogfeatures&s_tid=doc_srchtitle. The default parameters of the program selection, from Figure 1 can be previewed to the characteristics of each appropriate.