将Qt QByteArray转换为OpenCV cv :: InputArray

时间:2014-08-05 00:44:35

标签: qt opencv qt4 qt5

如何将Qt QByteArray转换为cv :: InputArray?

我需要传递一个自定义的特征向量:

// Constructor
HoGDetector::HoGDetector(QObject *parent) :
    QObject(parent)
{

    qDebug() << "Creating HoG Detector";

    // Set the SVM Detector ( Default OpenCV One )
    m_HoG.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());

    // Read
    QFile svmVectorFile(":/descriptorvector.dat");
    QByteArray svmVector = svmVectorFile.readAll();

    // Set the SVM Detector - custom trained HoG Detector
    m_HoG.setSVMDetector(svmVector);

}

谢谢!

1 个答案:

答案 0 :(得分:2)

OpenCV知道如何将std:vector转换为InputArray,所以这应该可以解决问题:

m_HoG.setSVMDetector(std::vector<uchar>(svmVector.begin(), svmVector.end()));