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

    
    
  • 相关阅读:
    [原]终于做了一个登陆页
    JDK 1.7环境变量的配置
    值类型和引用类型讲解,本人在大学时候的笔记,写给新手
    CDays2 习题一 (改进函数)及相关内容解析。Python 基础教程
    Winedt 7.0 Build: 20120321 永久试用方法 Winedt 7.0 破解
    Arduino 笔记。开篇
    What we find changes who we become.
    Python 中的POST/GET包构建以及随机字符串的生成。Python 初级应用
    CDays–2 完成核心功能 CMD模块 Python基础教程 cmd cli
    Python HDB3 AMI 编码与解码
  • 原文地址:https://www.cnblogs.com/newmiracle/p/15402163.html
Copyright © 2011-2022 走看看