Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

let's assume you want HuMoments for features,

for each contour, call [moments](,%20bool%20binaryImage)(contour) , and get the [HuMoments](,%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)