当前位置:   article > 正文

【python】Retinaface人脸检测与关键点定位识别数据集标注制作python_人脸关键点数据集怎么标注

人脸关键点数据集怎么标注

1.在制作人脸数据集的识别,往往需要制作标注自己的数据集,特征点可以自己定,所以写下这段代码,希望对你有所帮助。

2.用labelme做的标记,按照顺序:五个点+一个bbox

3.用labelme进行标注。

4.下面代码将xml文件转换为Retinaface训练集的label.txt。

5.也可以应用于工业特征点检测识别中。

  1. from xml.dom.minidom import parse
  2. import xml.dom.minidom
  3. import os
  4. # 使用minidom解析器打开 XML 文档
  5. # def parse_file(file_name,result_path):
  6. # DOMTree = xml.dom.minidom.parse(file_name)
  7. # collection = DOMTree.documentElement
  8. # shapes = collection.getElementsByTagName("shapes")
  9. # image_path=collection.getElementsByTagName("imagePath")[0].childNodes[0].nodeValue
  10. # with open(result_path,"a+",encoding="utf-8") as f:
  11. # f.writelines([image_path,"\n"])
  12. # temp=[]
  13. # for shape in shapes:
  14. # points=shape.getElementsByTagName("points")
  15. # for point in points:
  16. # value=point.childNodes[0].nodeValue
  17. # value=eval(value)
  18. # temp.append(str(value[0]))
  19. # temp.append(str(value[1]))
  20. # temp.append("0.0")
  21. # temp= temp[0:len(temp)-1]
  22. # temp.append("1")
  23. # line=" ".join(temp)
  24. # f.write(line)
  25. # f.write("\n")
  26. def parse_file(file_name,result_path):
  27. DOMTree = xml.dom.minidom.parse(file_name)
  28. collection = DOMTree.documentElement
  29. shapes = collection.getElementsByTagName("shapes")
  30. image_path=collection.getElementsByTagName("imagePath")[0].childNodes[0].nodeValue
  31. labels = dict()
  32. for shape in shapes:
  33. label=shape.getElementsByTagName("label")[0].childNodes[0].nodeValue
  34. label=eval(label)
  35. print(label)
  36. temp=labels.get(label,[])
  37. temp.append(shape)
  38. labels[label]=temp
  39. print(labels)
  40. line=""
  41. with open(result_path,"a+",encoding="utf-8") as f:
  42. f.writelines([image_path,])
  43. for label in labels:
  44. label_shapes=labels[label]
  45. shapes=[]
  46. for shape in label_shapes:
  47. points=shape.getElementsByTagName("points")
  48. temp=[]
  49. for point in points:
  50. value=point.childNodes[0].nodeValue
  51. value=eval(value)
  52. temp.append(str(value[0]))
  53. temp.append(str(value[1]))
  54. shapes.append(" ".join(temp))
  55. line+=(" 0.0 ".join(shapes)+' 1 ')
  56. f.write("\n")
  57. f.write(line)
  58. f.write("\n")
  59. def exchange(dir_path,result_file_path):
  60. # dirs=os.listdir("D:\projects\pycharm\experiments")
  61. dirs=os.listdir(dir_path)
  62. for file in dirs:
  63. print(file)
  64. parse_file(dir_path+'/'+file,result_file_path)
  65. print(dirs)
  66. if __name__ == '__main__':
  67. # 第一个参数是xml文件夹路径,第二个参数是txt文件路径,可以不存在
  68. exchange(r"D:\projects\pycharm\experiments\test",r"D:\projects\pycharm\experiments\result.txt")

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

闽ICP备14008679号