【问题标题】:opencv::Mat from vector of vectoropencv::Mat 来自向量的向量
【发布时间】:2013-02-20 01:53:59
【问题描述】:

我需要一些关于基于 svm 的分类器的帮助。我正在尝试从图像中计算 HOG 特征并使用它们来训练 svm。现在我有一个向量,其中的列包含每个图像的特征和行。为了训练 CvSVM,我需要一个具有特征的 Mat 矩阵。如何将向量的向量转换为具有相同形状的 Mat?

vector<vector<float>> totFeaturesVector;
for all images:
    vector<float> featuresVector;
    //populate featuresVector with 3780 floats...
    totFeaturesVector.push_back(featuresVector);
end for.
//numCols = 3780 numRows = 6.   6 images with 3780 features each. 

//Need to convert totFeaturesVector to 
//Mat training_mat(overallSamples,numCols,CV_32FC1); Something like this. 

【问题讨论】:

  • 向量的向量是什么?数值?
  • (a) 如何枚举你的向量> + (b) 如何填充特征矩阵 = (c) 如何将一个变成另一个。那你试过什么?
  • 抱歉这个含糊的问题。我有一个 6 行 3780 列的 vector>。我需要将其转换为垫子。我尝试了不同的构造函数,但我似乎无法做到正确。有什么想法吗?

标签: c++ opencv vector svm


【解决方案1】:

假设 final_output 是 6x3780 Mat

for(int i = 0; i < height; i++)
{
    for(int j = 0; j < width; j++)
    {
        final_output.at<float>(i,j) = vector[i][j];
    }
}

【讨论】:

  • OP 在其中一个问题的 cmets 中提到了这一点:“抱歉这个模糊的问题。我有一个 6 行 3780 列的向量>。我需要转换它进入垫子。我尝试了不同的构造函数,但我似乎无法正确。有什么想法吗?“
【解决方案2】:
vector<vector<float>> totFeaturesVector;
Mat_<float> M;
for (const auto & v: totFeaturesVector)
{
    Mat_<float> r(v), t=r.t(); // you need to do this
    M.push_back(t); // because push_back(Mat_<float>(v).t()) does not work
}

【讨论】:

  • 欢迎来到 Stack Overflow!请在您的回答中提供一些解释。尤其是因为这个问题已经有一个公认的答案,所以提供更多信息对您很有帮助。
猜你喜欢
  • 1970-01-01
  • 2013-09-02
  • 2013-10-05
  • 1970-01-01
  • 2012-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多