Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

indeed, there are more effective ways to setup your train data.

  • use cv::Mat consistently, not integer arrays
  • use builtin functions, not loops

Mat responses(510, 1, CV_32S, Scalar(1)); // i'm making up the numbers, but i hope, you get the idea, // initialize the whole labels Mat with your 1st label, then // set the other parts to the resp. label: responses(Range(100,200), Range::all()) = 2; responses(Range(200,510), Range::all()) = 3;

Mat data;

for each set of histograms: // combine the histograms Mat feature; hconcat(r_hist.reshape(1,1), g_hist.reshape(1,1), feature); data.push_back(feature);

indeed, there are more effective ways to setup your train data.

data.
  • * use cv::Mat consistently, not integer arrays
  • arrays * use builtin functions, not loops
loops

Mat responses(510, 1, CV_32S, Scalar(1)); // i'm making up the numbers, but i hope, you get the idea, // initialize the whole labels Mat with your 1st label, then // set the other parts to the resp. label: responses(Range(100,200), Range::all()) = 2; responses(Range(200,510), Range::all()) = 3;

3;

Mat data;

data;

for each set of histograms: // combine the histograms Mat feature; hconcat(r_hist.reshape(1,1), g_hist.reshape(1,1), feature); data.push_back(feature);

data.push_back(feature);
indeed, there are more effective ways to setup your train data.

* use cv::Mat consistently, not integer arrays
* use builtin functions, not loops


Mat responses(510, 1, CV_32S, Scalar(1)); 
// i'm making up the numbers, but i hope, you get the idea,
// initialize the whole labels Mat with your 1st label, then
// set the other parts to the resp. label:
responses(Range(100,200), Range::all()) = 2;
responses(Range(200,510), Range::all()) = 3;


Mat data;
// this assumes, you have a r_hist and a g_hist  // for each of your 510 input images
for each set of histograms:
   // combine the histograms
   Mat feature;
   // you can skip the reshape, if your hists are already "horizontal" (single column)
   hconcat(r_hist.reshape(1,1), g_hist.reshape(1,1), feature);
   data.push_back(feature);

// finally:
svm.train(data, ml::ROW_DATA, responses);
indeed, there are more effective ways to setup your train data.

* use cv::Mat consistently, not integer arrays
* use builtin functions, not loops


Mat responses(510, 1, CV_32S, Scalar(1)); 
// i'm making up the numbers, but i hope, you get the idea,
// initialize the whole labels Mat with your 1st label, then
// set the other parts to the resp. label:
responses(Range(100,200), Range::all()) = 2;
responses(Range(200,510), Range::all()) = 3;


Mat data;
// this assumes, you have a r_hist and a g_hist 
// for each of your 510 input images
for each set pair of histograms:
   // combine the histograms
histograms into a single, flat column:
   Mat feature;
   // you can skip the reshape, if your hists are already "horizontal" (single column)
   hconcat(r_hist.reshape(1,1), g_hist.reshape(1,1), feature);
   data.push_back(feature);

// finally:
svm.train(data, svm->train(data, ml::ROW_DATA, responses);
indeed, there are more effective ways to setup your train data.

* use cv::Mat consistently, not integer arrays
* use builtin functions, not loops


Mat responses(510, 1, CV_32S, Scalar(1)); 
// i'm making up the numbers, but i hope, you get the idea,
// initialize the whole labels Mat with your 1st label, then
// set the other parts to the resp. label:
responses(Range(100,200), Range::all()) = 2;
responses(Range(200,510), Range::all()) = 3;


Mat data;
// this assumes, you have a r_hist and a g_hist 
// for each of your 510 input images
for each pair of histograms:
   // combine the histograms into a single, flat column:
   Mat feature;
   // you can skip the reshape, if your hists are already "horizontal" (single column)
   hconcat(r_hist.reshape(1,1), g_hist.reshape(1,1), feature);
   data.push_back(feature);

// finally:
then:
svm->train(data, ml::ROW_DATA, responses);

// for prediction later, process your image in the very same way:
// get histograms, r_hist, g_hist, and combine them:
Mat feature;
hconcat(r_hist.reshape(1,1), g_hist.reshape(1,1), feature);

// prediction will be one of the labels, you fed in for training:
int prediction = (int) svm->predict(feature);