zoukankan      html  css  js  c++  java
  • python yolov5检测模型返回坐标的方法

    python yolov5检测模型返回坐标的方法 直接搜索以下代码替换下 

     if save_img or view_img:  # Add bbox to image
                            label = f'{names[int(cls)]} {conf:.2f}'
                            c1, c2 = (int(xyxy[0]), int(xyxy[1])), (int(xyxy[2]), int(xyxy[3]))
                            print("左上点的坐标为:(" + str(c1[0]) + "," + str(c1[1]) + "),右下点的坐标为(" + str(c2[0]) + "," + str(c2[1]) + ")")
                            return [c1,c2]
    
    

    if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--weights', nargs='+', type=str, default='yolov5s.pt', help='model.pt path(s)')
    parser.add_argument('--source', type=str, default='data/images', help='source') # file/folder, 0 for webcam
    parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
    parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold')
    parser.add_argument('--iou-thres', type=float, default=0.45, help='IOU threshold for NMS')
    parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
    parser.add_argument('--view-img', action='store_true', help='display results')
    parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
    parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels')
    parser.add_argument('--nosave', action='store_true', help='do not save images/videos')
    parser.add_argument('--classes', nargs='+', type=int, help='filter by class: --class 0, or --class 0 2 3')
    parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
    parser.add_argument('--augment', action='store_true', help='augmented inference')
    parser.add_argument('--update', action='store_true', help='update all models')
    parser.add_argument('--project', default='runs/detect', help='save results to project/name')
    parser.add_argument('--name', default='exp', help='save results to project/name')
    parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
    opt = parser.parse_args()

    check_requirements(exclude=('pycocotools', 'thop'))

    
    

    opt.source='data/images/1/'
    result=detect()
    print('最终检测结果:',result);

    
    
  • 相关阅读:
    HDU 1434 幸福列车(优先队列)
    HDU 4287 Intelligent IME(字典树)
    HDU 1671 Phone List(字典树)
    HDU 1711 Number Sequence(KMP匹配数字串)
    HDU 1251 统计难题(字典树计算前缀数量)
    HDU 2087 剪花布条(KMP基础应用)
    HRBUST 1909 理工门外的树(双数组实现线段树功能)
    HDU 1166 敌兵布阵(线段树)
    HDU 1754 I Hate It(线段树基础应用)
    HDU 1260 Tickets(基础dp)
  • 原文地址:https://www.cnblogs.com/newmiracle/p/15402163.html
Copyright © 2011-2022 走看看