Ask Your Question
0

How does work this code?

asked 2014-06-12 07:35:43 -0600

prince0fpersia gravatar image

updated 2014-06-12 07:40:07 -0600

Hi I can't understand how does work this line of following code:

Mat sampleMat = (Mat_<float>(1,2) << i,j);

what is "Mat_" ? Why (1,2)?

Vec3b green(0,255,0), blue (255,0,0);

for (int i = 0; i < image.rows; ++i)
    for (int j = 0; j < image.cols; ++j)
    {
    Mat sampleMat = (Mat_<float>(1,2) << i,j);
    float response = SVM.predict(sampleMat);

    if (response == 1)
       image.at<Vec3b>(j, i)  = green;
    else
    if (response == -1)
       image.at<Vec3b>(j, i)  = blue;
    }

Also why in if-else conditions it uses (j,i) not (i,j) ?

The complete explanation is exist here : http://docs.opencv.org/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.html

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-06-12 08:32:36 -0600

berak gravatar image

updated 2014-06-12 08:36:57 -0600

(j,i) is clearly wrong. it works in the demo, because width=height=512

the Mat_ line makes a 2 element mat, [i,j]. so the svm just predicts for every pixel position.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-06-12 07:35:43 -0600

Seen: 162 times

Last updated: Jun 12 '14