pip install labelimg\n<\/code><\/pre>\n\u8fdb\u5165cmd\uff0c\u8f93\u5165labelimg\uff0c\u4f1a\u51fa\u73b0\u5982\u56fe\u7684\u6807\u6ce8\u5de5\u5177\uff1a
<\/p>\n
2.\u6570\u636e\u96c6\u7684\u51c6\u5907<\/h3>\n
\u9996\u5148\u6211\u4eec\u5148\u521b\u5efa3\u4e2a\u6587\u4ef6\u5939\uff0c\u5982\u56fe\uff1a
DataImage\uff1a100\u5f20\u9700\u8981\u6807\u6ce8\u7684\u56fe\u50cf
DataLabel\uff1a\u7a7a\u6587\u4ef6\u5939\uff0c\u4e3b\u8981\u662f\u5b58\u653e\u6807\u6ce8\u6587\u4ef6\uff0c\u8fd9\u4e2a\u5728labelimg\u4e2d\u751f\u6210\u6807\u6ce8\u6587\u4ef6
test\uff1a\u5b58\u653e\u5269\u4e0b\u7684300\u5f20\u56fe\u7247\uff0c\u4e0d\u9700\u8981\u6807\u6ce8
DataImage\u76ee\u5f55\u4e0b\u548ctest\u76ee\u5f55\u7684\u5b58\u653e\u6837\u5b50\u662f\u8fd9\u6837\u7684\uff08\u4ee5DataImage\u4e3a\u4f8b\uff09\uff1a
<\/p>\n
3.\u6807\u6ce8\u6570\u636e<\/h3>\n
\u2003\u2003\u9996\u5148\u6211\u4eec\u9700\u8981\u5728labelimg\u4e2d\u8bbe\u7f6e\u56fe\u50cf\u8def\u5f84\u548c\u6807\u7b7e\u5b58\u653e\u8def\u5f84\uff0c\u5982\u56fe\uff1a
\u2003\u2003\u7136\u540e\u5148\u8bb0\u4f4f\u5feb\u6377\u952e\uff1aw\uff1a\u5f00\u59cb\u7f16\u8f91\uff0ca:\u4e0a\u4e00\u5f20\uff0cd:\u4e0b\u4e00\u5f20\u3002\u8fd9\u4e2a\u5de5\u5177\u53ea\u9700\u8981\u8fd9\u4e09\u4e2a\u5feb\u6377\u952e\u5373\u53ef\u5b8c\u6210\u5de5\u4f5c\u3002
\u2003\u2003\u5f00\u59cb\u6807\u6ce8\u5de5\u4f5c\uff0c\u9996\u5148\u6309\u4e0b\u952e\u76d8w\uff0c\u8fd9\u4e2a\u65f6\u5019\u8fdb\u5165\u7f16\u8f91\u6846\u6846\u7684\u6a21\u5f0f\uff0c\u7136\u540e\u5728\u56fe\u50cf\u4e0a\u7ed8\u5236\u6846\u6846\uff0c\u8f93\u5165\u6807\u7b7e\uff08\u6846\u6846\u5c5e\u4e8e\u4ec0\u4e48\u7c7b\u522b\uff09\uff0c\u5373\u53ef\u5b8c\u6210\u7269\u4f531\u7684\u6807\u6ce8\uff0c\u4e00\u5f20\u7269\u4f53\u53ef\u4ee5\u591a\u4e2a\u6807\u6ce8\u548c\u591a\u4e2a\u7c7b\u522b\uff0c\u4f46\u662f\u5207\u8bb0\u4e0d\u53ef\u6478\u68f1\u4e24\u53ef\uff0c\u6bd4\u5982\u8fd9\u5f20\u56fe\u50cf\u5bf9\u4e8e\u67d0\u7269\u4f53\u6807\u6ce8\u4e86\uff0c\u53e6\u4e00\u5f20\u56fe\u50cf\u5982\u679c\u51fa\u73b0\u540c\u6837\u7684\u5c31\u9700\u8981\u6807\u6ce8\uff0c\u6216\u8005\u6807\u7b7e\u7c7b\u522b\u4e0d\u53ef\u591a\u4e2a\uff0c\u6bd4\u5982\u8fd9\u4e2a\u56fe\u8c61A\u7269\u4f53\u6807\u6ce8\u4e3aA\u6807\u7b7e\uff0c\u4e0b\u5f20\u56fe\u7684A\u7269\u4f53\u6807\u51fa\u6210\u4e86B\u6807\u7b7e\uff0c\u6700\u7ec8\u7684\u6548\u679c\u5982\u56fe\uff1a
\u6700\u540e\u6807\u6ce8\u5b8c\u6210\u4f1a\u5728DataLabel\u4e2d\u770b\u5230\u6807\u6ce8\u6587\u4ef6\uff0cjson\u683c\u5f0f\uff1a
<\/p>\n
4.\u89e3\u91caxml\u6587\u4ef6\u7684\u5185\u5bb9<\/h3>\n
xml\u6807\u7b7e\u6587\u4ef6\u5982\u56fe\uff0c\u6211\u4eec\u7528\u5230\u7684\u5c31\u53ea\u6709object\u5bf9\u8c61\uff0c\u5bf9\u5176\u8fdb\u884c\u89e3\u6790\u5373\u53ef\u3002<\/p>\n
\n\u4e8c\u3001\u6570\u636e\u8f6c\u6362<\/h2>\n
\u6570\u636e\u8f6c\u6362\u5206\u4e3a\u4e24\u6b65\uff0c\u9996\u5148\u4f7f\u7528python\u811a\u672c\u89e3\u6790xml\u6587\u4ef6\uff0c\u7136\u540e\u4f7f\u7528hdev\u811a\u672c\u5b9e\u73b0halcon\u8bad\u7ec3\u6240\u9700\u8981\u7684\u8bad\u7ec3\u6587\u4ef6<\/p>\n
1.\u89e3\u6790XML\u6587\u4ef6<\/h3>\n
\u6b64\u5904\u89e3\u6790xml\uff0c\u63d0\u53d6\u6bcf\u5f20\u56fe\u50cf\u7684\u76ee\u6807\u7c7b\u522b\u53ca\u4f4d\u7f6e<\/p>\n
with<\/span> open<\/span>(<\/span>xmlfile,<\/span> \"r\"<\/span>,<\/span> encoding=<\/span>\"utf-8\"<\/span>)<\/span> as<\/span> in_file:<\/span>\n tree =<\/span> ET.<\/span>parse(<\/span>in_file)<\/span>\n root =<\/span> tree.<\/span>getroot(<\/span>)<\/span>\n\n for<\/span> obj in<\/span> root.<\/span>iter<\/span>(<\/span>'object'<\/span>)<\/span>:<\/span>\n cls =<\/span> obj.<\/span>find(<\/span>'name'<\/span>)<\/span>.<\/span>text\n if<\/span> cls not<\/span> in<\/span> classes:<\/span>\n classes.<\/span>append(<\/span>cls)<\/span>\n cls_id =<\/span> classes.<\/span>index(<\/span>cls)<\/span>\n xmlbox =<\/span> obj.<\/span>find(<\/span>'bndbox'<\/span>)<\/span>\n b =<\/span> (<\/span>int<\/span>(<\/span>xmlbox.<\/span>find(<\/span>'xmin'<\/span>)<\/span>.<\/span>text)<\/span>,<\/span>int<\/span>(<\/span>xmlbox.<\/span>find(<\/span>'ymin'<\/span>)<\/span>.<\/span>text)<\/span>,<\/span> int<\/span>(<\/span>xmlbox.<\/span>find(<\/span>'xmax'<\/span>)<\/span>.<\/span>text)<\/span>,<\/span>int<\/span>(<\/span>xmlbox.<\/span>find(<\/span>'ymax'<\/span>)<\/span>.<\/span>text)<\/span>)<\/span>\n list_file +=<\/span> \" \"<\/span> +<\/span> \",\"<\/span>.<\/span>join(<\/span>[<\/span>str<\/span>(<\/span>a)<\/span> for<\/span> a in<\/span> b]<\/span>)<\/span> +<\/span> ','<\/span> +<\/span> str<\/span>(<\/span>cls_id)<\/span>\n if<\/span> cls not<\/span> in<\/span> label_name_dict:<\/span>\n label_name_dict[<\/span>cls]<\/span>=<\/span>0<\/span>\n label_name_dict[<\/span>cls]<\/span>+=<\/span>1<\/span>\n TrainDataList.<\/span>append(<\/span>list_file)<\/span>\n\nwith<\/span> open<\/span>(<\/span>os.<\/span>path.<\/span>join(<\/span>SaveDir,<\/span>'classes.txt'<\/span>)<\/span>,<\/span> encoding=<\/span>\"utf-8\"<\/span>,<\/span> mode=<\/span>\"w\"<\/span>)<\/span> as<\/span> f:<\/span>\n for<\/span> each in<\/span> range<\/span>(<\/span>len<\/span>(<\/span>classes)<\/span>)<\/span>:<\/span>\n f.<\/span>write(<\/span>classes[<\/span>each]<\/span> +<\/span> \"\\n\"<\/span>)<\/span>\n\nwith<\/span> open<\/span>(<\/span>os.<\/span>path.<\/span>join(<\/span>SaveDir,<\/span>'TrainList.txt'<\/span>)<\/span>,<\/span> encoding=<\/span>\"utf-8\"<\/span>,<\/span> mode=<\/span>\"w\"<\/span>)<\/span> as<\/span> f:<\/span>\n for<\/span> each in<\/span> TrainDataList:<\/span>\n f.<\/span>write(<\/span>each +<\/span> \"\\n\"<\/span>)<\/span>\n<\/code><\/pre>\n\u6700
\u540e\u5f97\u5230\u7684\u6548\u679c\u4e3b\u8981\u662f\u4e24\u4e2atxt\u6587\u4ef6\uff1a
\u2018TrainList.txt\u2019\uff1a\u8bad\u7ec3\u6570\u636e
\u2018classes.txt\u2019\uff1a\u7c7b\u522b\u6570\u636e
\u5982\u56fe\uff1a
<\/p>\n
<\/p>\n
2.\u8f6c\u6362\u5f97\u5230hdev\u6587\u4ef6<\/h3>\n1.\u53d8\u91cf\u5b9a\u4e49<\/h4>\n*<\/span> \u524d\u8fb9\u751f\u6210\u7684\u7c7b\u522b\u6587\u4ef6\nclass_txt:=<\/span>'..\/DataSet\/Temp_DetDataSet\/classes.txt'<\/span>\n*<\/span> \u524d\u8fb9\u751f\u6210\u7684\u6570\u636e\u6807\u6ce8\u6587\u4ef6\ntrain_txt:=<\/span>'..\/DataSet\/Temp_DetDataSet\/TrainList.txt'<\/span>\n*<\/span> \u57fa\u4e8ehalcon\u8f6c\u5316\u811a\u672c\u4e0b\u7684\u56fe\u50cf\u4fdd\u5b58\u8def\u5f84\nImageDir:=<\/span>'..\/DataSet\/DataImage'<\/span>\n*<\/span> \u57fa\u4e8ehalcon\u8bad\u7ec3\u811a\u672c\u4e0b\u7684\u56fe\u50cf\u4fdd\u5b58\u8def\u5f84\nBaseImgDir:=<\/span>'.\/DataSet\/DataImage'<\/span>\n*<\/span> \u4fdd\u5b58\u4e3ahalcon\u8bc6\u522b\u7684\u8bad\u7ec3\u6587\u4ef6\ndict_File:=<\/span>'..\/DataSet\/Temp_DetDataSet\/dl_dataset.hdict'<\/span>\n<\/code><\/pre>\n2.\u8bfb\u53d6\u79cd\u7c7b<\/h4>\nopen_file (<\/span>class_txt,<\/span> 'input'<\/span>,<\/span> FileHandle)<\/span>\nrepeat\n fread_line(<\/span>FileHandle,<\/span> oneline,<\/span> IsEOF)<\/span>\n if<\/span>(<\/span>IsEOF ==<\/span> 1<\/span>)<\/span>\n break<\/span> \n endif\n if<\/span>(<\/span>oneline ==<\/span> ' '<\/span> or<\/span> oneline==<\/span>'\\n'<\/span>)<\/span>\n continue<\/span>\n endif\n tuple_regexp_replace (<\/span>oneline