这段代码是如何工作的?(SVM分类) [英] How does this code work?(SVM classification)

查看:88
本文介绍了这段代码是如何工作的?(SVM分类)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我无法理解这行以下代码是如何工作的:



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



什么是Mat_?

为什么(1,2)?







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;
    }





为什么在if-else条件下它使用(j,i)not(i, j)?



这里有完整的解释:http://docs.opencv.org/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.html



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

推荐答案

Mat是Matrice的缩写形式,它是用于在openCV中存储图像和其他内容的中心类型。如果你想使用openCV,你应该真正学习那些基础知识。 openCV的文档非常好。例如,请参见:

http://docs.opencv.org/modules /core/doc/basic_structures.html [ ^ ]



使用代码中显示的构造函数:

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

您创建一个包含2个元素(1行,2列)的矩阵,并将i和j的值存储到其中。



为什么在if-else条件下它使用(j,i)不是(i,j)?

你是对的它应该用(i,j)编入索引,事实上这就是你在教程中所做的事情。

ve链接。所以在复制代码时你似乎犯了一个错误。
Mat is short form for "Matrice" and it is the central type used to store images and other things in openCV. You should really learn those very basics if you want to work with openCV. The documentation of openCV is quite good. See for example here:
http://docs.opencv.org/modules/core/doc/basic_structures.html[^]

With the constructor as shown in your code:
Mat sampleMat = (Mat_<float>(1,2) << i,j);
you create a matrice with 2 elements (1 row, 2 columns) and store the values of i and j into it.

"Also why in if-else conditions it uses (j,i) not (i,j) ?"
You're right it should be indexed with (i, j) and in fact that's what is done in the tutorial you'
ve linked. So it seems you made a mistake there when copying the code.


这篇关于这段代码是如何工作的?(SVM分类)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆