QT+opencv4.5.4+yolov5+目标检测

之前做过yolov3、yolov4+opencv进行检测,yolov5出道了v6版本的时候,开始支持dnn模块,所以下载试试,

环境:opencv4.5.4     CUDA:10.2      QT:5.9

yolov5大家可以从git上clone,这里使用的是yolov5s.pt模型。给他转换为onnx

    cap>>img;
    vector<Scalar> color;
    srand(time(0));
    for (int i = 0; i < 80; i++) {
        int b = rand() % 256;
        int g = rand() % 256;
        int r = rand() % 256;
        color.push_back(Scalar(0, 0, 255));
    }
    QImage Qimg1=mat2QImage(img);
    ui->label->setScaledContents(true);
    ui->label->setPixmap(QPixmap::fromImage(Qimg1));
    vector<Output> result;
    if (test.Detect(img, net, result)) {
      img= test.drawPred(img, result, color);
      QImage Qimg2=mat2QImage(img);
       ui->label_2->setScaledContents(true);
      ui->label_2->setPixmap(QPixmap::fromImage(Qimg2));
      waitKey(10);
    }
    else {
       cout << "Detect Failed!" << endl;
    }

结果:

猜你喜欢

转载自blog.csdn.net/zhangdaoliang1/article/details/121289705