1 | initial version |
let's assume you want HuMoments for features,
for each contour, call [moments](http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#Moments%20moments(InputArray%20array,%20bool%20binaryImage)(contour) , and get the [HuMoments](http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#void%20HuMoments(const%20Moments&%20moments,%20double%20hu[7]) from that .
voila, now you got a 7 element feature vector per contour ( remember the demo above ? they had 2element features(points), you got 7element 'points' here.
probably the most easy way, to build the traindata and the trainlabels mats is to start with empty Mat's for both, and just push_back() the 7 humoments, one after the other into the traindatamat, and to push_back() 1 label into the trainlabels.
after you collected all your data, you just call traindata=traindata.reshape(1,num_train_items)
to make a 2d Mat of it. in the end , it should look like this:
traindata trainlabels
h0 h1 h2 h3 h4 h5 h6 4
h0 h1 h2 h3 h4 h5 h6 1
h0 h1 h2 h3 h4 h5 h6 9
h0 h1 h2 h3 h4 h5 h6 13
...
(num_train_items rows of 7 elm) (num_train_items rows of 1 elm)