win10 openvino的IE推理引擎加速caffemodel


int main(int argc, char** argv) {
    tf_bin_load();
    Mat src = imread("D:\\okay_workspace\\project_data\\test01.jpg");
    //resizeWindow();
    //imshow("ori", src);
    
    if (src.empty()) {
        printf("load image error......");
    }
    //Net net=readNetFromTensorflow()
    Net net = readNetFromCaffe(pbtxt_path, model_path);
    //使用openvino inference_engine infer,default:DNN_BACKEND_OPENCV,DNN_BACKEND_INFERENCE_ENGINE
    net.setPreferableBackend(DNN_BACKEND_INFERENCE_ENGINE);//设置计算后台
    net.setPreferableTarget(DNN_TARGET_CPU);//指定IOT设备运行环境
                                                           // image-->bob tensor
    printf("start load peleeeNet ....\n");
    //caffe python: blob = dnn.blobFromImage(img_ori, 0.017, (304, 304), (103.94, 116.78, 123.68))
    Mat blob = blobFromImage(src, 0.017, Size(304, 304), Scalar(103.94, 116.78, 123.68),true,false,5);
    net.setInput(blob);
    
    Mat detection = net.forward();
    
    //获取infer时间
    vector<double>layerTimings;//
    double freq = getTickFrequency() / 1000;
    double time = net.getPerfProfile(layerTimings) / freq;//net.getPerfProfile(layerTimings)返回每一层infer时间
    ostringstream ss;
    ss << "inference:" << time << "ms";
    putText(src, ss.str(), Point(60, 200), FONT_HERSHEY_COMPLEX, 3, Scalar(255, 0, 0), 2, 8);
                                                          //0:index,1:class_name,2:score,boxes(3,4,5,6)
    // h,w
    float threshold = 0.25;

    Mat detectionMat(detection.size[2],detection.size[3],CV_32F,detection.ptr<float>());
    
    
    //detectionMat = detectionMat.size[0];
    for (int i = 0; i < detectionMat.rows; i++) {
        float confidence = detectionMat.at<float>(i, 2);
        if (confidence > threshold) {
            rsize_t object_index = (rsize_t)detectionMat.at<float>(i,1);
            //xmin,ymin,xmax,ymax
            float xmin = detectionMat.at<float>(i, 3)*src.cols;
            float ymin = detectionMat.at<float>(i, 4)*src.rows;
            float xmax = detectionMat.at<float>(i, 5)*src.cols;
            float ymax = detectionMat.at<float>(i, 6)*src.rows;
            Rect object_box((int)xmin, (int)ymin, (int)(xmax-xmin),(int)(ymax-ymin));
            rectangle(src, object_box, Scalar(0, 255, 0), 2,8,0);
        }
    
    }
    namedWindow("peleeNet_detection",0);
    resizeWindow("peleeNet_detection",Size(800,1000));//h,w

    imshow("peleeNet_detection", src);
    waitKey(0);
    destroyAllWindows();
    return 0;
    
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值