qt - 将 Qt QByteArray 转换为 OpenCV cv::InputArray

标签 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);

}

谢谢!

最佳答案

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

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

关于qt - 将 Qt QByteArray 转换为 OpenCV cv::InputArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25129653/

相关文章:

c++ - 传递 mat 引用时出现 opencv malloc 错误

c++ - 在 QMainWindow 中显示 QGridLayout

c++ - QT GUI 进度条

c++ - 从计算机向计算机发送 XML 数据 - Qt

qt - Q_GADGET 未知方法返回类型

c++ - 如何使用软件程序(如yahoo messenger)向手机发送短信?

python-3.x - 属性错误 : module 'cv2.cv2' has no attribute 'release'

c++ - 在不调用 QApplication::exec() 的情况下显示小部件的正确方法是什么?

python - 如何在没有数据或彩色图像的情况下获得清晰的图像。 opencv python

c++ - 在构建基于 C++ 的软件中包含 QtGui 文件的问题