当前位置:   article > 正文

yolov8-pose,labelme关键点标注及格式转换_yolov8关键点标注

yolov8关键点标注

目录

一、代码、权重下载

二、标注规则

三、标注要求及步骤

四、json标签样式

五、json转txt格式


一、代码、权重下载

YOLOv8代码:ultralytics/ultralytics首页 - GitCode

环境安装

pip install ultralytics

 

关键点训练权重下载:

https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n-pose.pt

https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8s-pose.pt

https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8m-pose.pt

https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8l-pose.pt

https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8x-pose.pt

 https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8x-pose-p6.pt

 

二、标注规则

标签组成:类型,1个数据;目标框坐标,4个数据;关键点,n*3个数据(n为关键点个数,'3'为坐标及是否可见,点标签:0代表此点不在图像上,点标签:1   代表此点在图像上且在未遮挡处,点标签:2   代表此点在图像上但在遮挡处)

  1. 0 0.07390752032520326 0.5280939476061427 0.1384654471544715 0.22244805781391144 0.14059959349593495 0.5489837398373983 0 0.04024390243902439 0.5354336043360434 2 0.006580284552845528 0.6133468834688347 1 0.11709857723577236 0.6122177055103883 1
  2. 0 0.11709857723577234 0.30451671183378504 0.0431910569105691 0.09146341463414637 0.10312499999999998 0.3163730803974706 2 0.10566565040650407 0.32540650406504057 1 0.13678861788617885 0.3220189701897019 0 0.13678861788617885 0.3141147244805781 0
  3. 0 0.7535315040650405 0.857813911472448 0.49034552845528445 0.28116531165311665 0.8964430894308942 0.99726738934056 0 0.9967987804878048 0.9679087624209575 0 0.6404725609756097 0.8753161698283649 2 0.5108993902439024 0.9679087624209575 1
  4. 0 0.982981220657277 0.212245696400626 0.02787558685446001 0.06585811163275952 0.9807805164319249 0.220396452790819 2 0.9697769953051644 0.220396452790819 0 0.9705105633802817 0.22691705790297342 0 0.9936179577464789 0.22756911841418886 1

三、标注要求及步骤

(1)标注工具:labelme

(2)按顺序先标注车辆长方形包围拉框,再标记车辆ABCD四个顶点(备注 :若拉框顺序与标点顺序反了,请重新标注)

(3)四个车底盘顶点顺序

    逆时针:A点、B点、C点、D点

4顶点标签

    0表示没有显露出不可见,1表示可见,2表示被遮挡不可见

四、json标签样式

  1. {
  2. "version": "5.0.1",
  3. "flags": {},
  4. "shapes": [
  5. {
  6. "label": "car",
  7. "points": [
  8. [
  9. 8.97560975609756,
  10. 450.2195121951219
  11. ],
  12. [
  13. 274.8292682926829,
  14. 690.4634146341463
  15. ]
  16. ],
  17. "group_id": null,
  18. "shape_type": "rectangle",
  19. "flags": {}
  20. },
  21. {
  22. "label": "0",
  23. "points": [
  24. [
  25. 269.9512195121951,
  26. 592.9024390243902
  27. ]
  28. ],
  29. "group_id": null,
  30. "shape_type": "point",
  31. "flags": {}
  32. },
  33. {
  34. "label": "2",
  35. "points": [
  36. [
  37. 77.26829268292683,
  38. 578.2682926829268
  39. ]
  40. ],
  41. "group_id": null,
  42. "shape_type": "point",
  43. "flags": {}
  44. },
  45. {
  46. "label": "1",
  47. "points": [
  48. [
  49. 12.634146341463413,
  50. 662.4146341463414
  51. ]
  52. ],
  53. "group_id": null,
  54. "shape_type": "point",
  55. "flags": {}
  56. },
  57. {
  58. "label": "1",
  59. "points": [
  60. [
  61. 224.8292682926829,
  62. 661.1951219512194
  63. ]
  64. ],
  65. "group_id": null,
  66. "shape_type": "point",
  67. "flags": {}
  68. }
  69. ],
  70. "imagePath": "1127_52.jpg",
  71. "imageData":
  72. "imageHeight": 1080,
  73. "imageWidth": 1920
  74. }

五、json转txt格式

     要求:标注步骤必须按照先拉框,然后按逆时针标注关键点生成json文件

  转换脚本

  1. import json
  2. import os
  3. import argparse
  4. import cv2
  5. from tqdm import tqdm
  6. import numpy as np
  7. #标签类别字典
  8. # 0: car
  9. dictlist=['car']
  10. def convert(img_size, box):
  11. dw = 1. / (img_size[0])
  12. dh = 1. / (img_size[1])
  13. x = (box[0] + box[2]) / 2.0
  14. y = (box[1] + box[3]) / 2.0
  15. w = abs(box[2] - box[0])
  16. h = abs(box[3] - box[1])
  17. x = x * dw
  18. w = w * dw
  19. y = y * dh
  20. h = h * dh
  21. return (x, y, w, h)
  22. def convert_label_json(json_dir, img_path, save_dir):
  23. json_paths = os.listdir(json_dir)
  24. for json_path in tqdm(json_paths):
  25. path = os.path.join(json_dir,json_path)
  26. with open(path,'r',encoding='UTF-8') as load_f:
  27. json_dict = json.load(load_f)
  28. img_w = json_dict['imageWidth'] # 图片的高
  29. img_h = json_dict['imageHeight'] # 图片的宽
  30. txt_path = os.path.join(save_dir, json_path.replace('json', 'txt'))
  31. with open(txt_path, 'w') as txt_file:
  32. points_nor_list = []
  33. fournum=1
  34. for shape_dict in json_dict["shapes"]:
  35. if shape_dict["shape_type"]=="rectangle":
  36. x1 = float(shape_dict['points'][0][0])
  37. y1 = float(shape_dict['points'][0][1])
  38. x2 = float(shape_dict['points'][1][0])
  39. y2 = float(shape_dict['points'][1][1])
  40. bb = (x1, y1, x2, y2)
  41. bbox = convert((img_w, img_h), bb)
  42. label1=shape_dict["label"]
  43. no_0=dictlist.index(label1)
  44. line=np.append(str(no_0),bbox)
  45. if shape_dict["shape_type"]=="point":
  46. x0=float(shape_dict['points'][0][0])/img_w
  47. y0=float(shape_dict['points'][0][1])/img_h
  48. pointlist=[x0,y0,shape_dict["label"]]
  49. line=np.append(line,pointlist)
  50. if fournum%5==0:
  51. stringline=' '.join(line)
  52. stringline=stringline+'\n'
  53. txt_file.writelines(stringline)
  54. fournum+=1
  55. if __name__ == "__main__":
  56. parser = argparse.ArgumentParser(description='json convert to txt params')
  57. parser.add_argument('--json-dir', type=str, default=r"C:xxxxxxxxxxxxx", help='json path dir')#标签路径
  58. parser.add_argument('--img-path', type=str, default=r"C:xxxxxxxxxxxxx", help='json path dir')#图片路径
  59. parser.add_argument('--save-dir', type=str, default=r"C:xxxxxxxxxxxxx", help='txt save dir')#txt保存路径
  60. args = parser.parse_args()
  61. json_dir = args.json_dir
  62. img_path = args.img_path
  63. save_dir = args.save_dir
  64. convert_label_json(json_dir, img_path, save_dir)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/474291
推荐阅读
相关标签
  

闽ICP备14008679号