使用openvino工具包随附的模型,但无效

时间:2019-08-09 13:46:16

标签: c++ qt opencv openvino

在Qt项目中设置了openvino环境后,我使用download.py下载了几个openvino模型,并在程序中调用了它们,但它们不起作用。

openvino的版本为openvino_2019.2.242。 QT项目中与openvino相关的环境是:

INCLUDEPATH+= \
    /opt/intel/openvino/opencv/include \
    /opt/intel/openvino/deployment_tools/inference_engine/include \
    /opt/intel/openvino/opencv

LIBS += \
    /opt/intel/openvino/opencv/lib/* \  
    -L/opt/intel/openvino/opencv/lib \  
    -L/opt/intel/openvino/deployment_tools/inference_engine/lib/intel64 \  
    -L/opt/intel/openvino/openvx/lib \  
    -L/opt/intel/openvino/deployment_tools/inference_engine/external/mkltiny_lnx/lib \
    -linference_engine \
    -liomp5 \
    -lMKLDNNPlugin \
    -lmkl_tiny_tbb

以下是项目中的相关代码:

    int backendId = cv::dnn::DNN_BACKEND_INFERENCE_ENGINE;
    int targetId = cv::dnn::DNN_TARGET_CPU;
    net = readNet("/home/dylan/openvino_models/Security/object_detection/barrier/0106/dldt/FP32/vehicle-license-plate-detection-barrier-0106.xml",
                                 "/home/dylan/openvino_models/Security/object_detection/barrier/0106/dldt/FP32/vehicle-license-plate-detection-barrier-0106.bin");
    net.setPreferableBackend(backendId);
    net.setPreferableTarget(targetId);
    Mat inputBlob = blobFromImage(my_frame[0], inScaleFactor, Size(inWidth, inHeight), Scalar(meanVal, meanVal, meanVal), false, false);
    net.setInput(inputBlob);
    Mat detection = net.forward();
    Mat detectionMat(detection.size[2], detection.size[3], CV_32F,
                     detection.ptr<float>());
    cout << detectionMat << endl;
    for (int i = 0; i < detectionMat.rows; i++) {
        float confidence = detectionMat.at<float>(i, 2);
        if (confidence > confidenceThreshold) {
            size_t objectClass = (size_t)(detectionMat.at<float>(i, 1));
            int tl_x =
                static_cast<int>(detectionMat.at<float>(i, 3) * my_frame[0].cols);
            int tl_y =
                static_cast<int>(detectionMat.at<float>(i, 4) * my_frame[0].rows);
            int br_x =
                static_cast<int>(detectionMat.at<float>(i, 5) * my_frame[0].cols);
            int br_y =
                static_cast<int>(detectionMat.at<float>(i, 6) * my_frame[0].rows);
            rectangle(my_frame[1], Point(tl_x, tl_y), Point(br_x, br_y), Scalar(0, 0, 255), 3);
            number[0] += 1;
        }
    }

detectionMat是一个200×7的矩阵。输出后,发现除了[0] [0]为-1外,其余均为0。

0 个答案:

没有答案