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

    
    
  • 相关阅读:
    获取 iPhone 上联系人姓名、电话、邮件的代码
    NSDate常用代码范例
    iphone开发之多线程NSThread和NSInvocationOperation
    iphone 定时提醒
    iphone 程序自动登陆
    搞定大厂算法面试之leetcode精讲11剪枝&回溯
    大厂算法面试之leetcode精讲7.双指针
    大厂算法面试之leetcode精讲8.滑动窗口
    大厂算法面试之leetcode精讲15.链表
    大厂算法面试之leetcode精讲10.递归&分治
  • 原文地址:https://www.cnblogs.com/newmiracle/p/15402163.html
Copyright © 2011-2022 走看看