網站首頁 編程語言 正文
找到detect.py,在大概113行,找到plot_one_box
? ? ? ? ? ? ? ? # Write results ? ? ? ? ? ? ? ? for *xyxy, conf, cls in reversed(det): ? ? ? ? ? ? ? ? ? ? if save_txt: ?# Write to file ? ? ? ? ? ? ? ? ? ? ? ? xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() ?# normalized xywh ? ? ? ? ? ? ? ? ? ? ? ? with open(txt_path + '.txt', 'a') as f: ? ? ? ? ? ? ? ? ? ? ? ? ? ? f.write(('%g ' * 5 + '\n') % (cls, *xywh)) ?# label format ? ? ? ? ? ? ? ? ? ? if save_img or view_img: ?# Add bbox to image ? ? ? ? ? ? ? ? ? ? ? ? label = '%s %.2f' % (names[int(cls)], conf) ? ? ? ? ? ? ? ? ? ? ? ? plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=3)
ctr+鼠標點擊,進入general.py,并自動定位到plot_one_box函數,修改函數為
def plot_one_box(x, img, color=None, label=None, line_thickness=None): # Plots one bounding box on image img tl = line_thickness or round(0.002 * (img.shape[0] + img.shape[1]) / 2) + 1 # line/font thickness color = color or [random.randint(0, 255) for _ in range(3)] c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3])) cv2.rectangle(img, c1, c2, color, thickness=tl, lineType=cv2.LINE_AA) print("左上點的坐標為:(" + str(c1[0]) + "," + str(c1[1]) + "),右下點的坐標為(" + str(c2[0]) + "," + str(c2[1]) + ")")
即可輸出目標坐標信息了
附: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);
總結
原文鏈接:https://blog.csdn.net/weixin_44612221/article/details/115384742
相關推薦
- 2022-07-06 YOLOv5目標檢測之anchor設定_python
- 2022-10-16 Android基于方法池與回調實現登錄攔截的場景_Android
- 2023-03-16 PostgreSQL?復制表的?5?種方式詳解_PostgreSQL
- 2022-05-20 使用nginx+tomcat+keepalived實現高可用的詳細步驟_nginx
- 2022-11-30 React之錯誤邊界?Error?Boundaries示例詳解_React
- 2022-07-09 Python實現功能全面的學生管理系統_python
- 2023-03-05 Python中ConfigParser模塊示例詳解_python
- 2022-12-11 docke-cli的調試環境搭建過程_docker
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支