{"id":15934884,"url":"https://github.com/pinto0309/yolotraindatagenerate","last_synced_at":"2026-05-05T20:35:01.969Z","repository":{"id":97173332,"uuid":"127596815","full_name":"PINTO0309/YoloTrainDataGenerate","owner":"PINTO0309","description":"Procedures and tools for semi-mechanically automatically generating YoloV2 original learning data from video.","archived":false,"fork":false,"pushed_at":"2021-03-26T00:16:51.000Z","size":201,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-29T08:21:08.783Z","etag":null,"topics":["ffmpeg","opencv","python","yolov2"],"latest_commit_sha":null,"homepage":"https://qiita.com/PINTO/items/d5645734ca9c95b1c395","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PINTO0309.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-01T04:26:57.000Z","updated_at":"2021-10-25T06:41:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"ad7eb9ac-af3e-4eeb-a5ce-66dc5913d0f2","html_url":"https://github.com/PINTO0309/YoloTrainDataGenerate","commit_stats":{"total_commits":34,"total_committers":2,"mean_commits":17.0,"dds":0.3529411764705882,"last_synced_commit":"637db256ac4e29d05299ef55c8961dfbfb6c3363"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2FYoloTrainDataGenerate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2FYoloTrainDataGenerate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2FYoloTrainDataGenerate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PINTO0309%2FYoloTrainDataGenerate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PINTO0309","download_url":"https://codeload.github.com/PINTO0309/YoloTrainDataGenerate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247024152,"owners_count":20870940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ffmpeg","opencv","python","yolov2"],"created_at":"2024-10-07T03:21:33.514Z","updated_at":"2026-05-05T20:35:01.937Z","avatar_url":"https://github.com/PINTO0309.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [Japanese] YoloTrainDataGenerate\n動画からYoloV2独自学習データを半機械的に自動生成するための手順とツール\u003cbr\u003e\nProcedures and tools for semi-mechanically automatically generating YoloV2 original learning data from video\u003cbr\u003e\nhttps://qiita.com/PINTO/items/d5645734ca9c95b1c395\n\n　\n# 環境\n* CPU：第3世代 Intel Core i7-3517U(1.9GHz)\n* MEM：16GB\n* GPU：Geforce GT 650M (VRAM:2GB)\n* OS：Ubuntu 16.04 LTS\n* OpenCV 3.4.1\n* ffmpeg\n* Samba\n* pyrenamer\n\n　\n# おおまかな流れ\n1. 適当に動画撮影\n2. 動画から機械的に静止画を大量生成\n3. 大量の静止画から物体部分を機械的に抽出して背景が透過した物体画像生成\n4. 別途用意した背景静止画と 3. で生成した物体静止画をランダムに回転・縮小・拡大・配置・ノイズ追加しながら合成して大量に水増し\n\n　\n# 動画→静止画変換\n下記コマンドにより動画から生成したpngファイルを「YoloTrainDataGenerate/images_org/」へコピー\u003cbr\u003e\n`$ ffmpeg -i xxxx.mp4 -vcodec png -r 10 image_%04d.png`\n\n　\n# 複数静止画ファイル、複数物体周囲を機械的に一括透過加工\n* 背景が白色に近い色・物体が白色／灰色以外の配色で構成されている場合のみ動作\n* １画像内に複数物体が写っている場合は物体数分の画像ファイルへ分割して加工\n* 入力画像が長方形であっても最終生成画像は物体を含む96×96の正方形\n* エッジ抽出の都合上、重なり合っている物体は１つと認識される\n* 検出された物体の面積が1000pxに満たない場合は当該物体を抽出対象から除外\n* 最終生成された画像内に物体が存在しないと判断される場合はファイルを生成しない\n```\n$ cd YoloTrainDataGenerate\n$ python3 object_extraction.py\n```\n(1) 編集元画像 1920x1080\u003cbr\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![1.png](https://github.com/PINTO0309/YoloTrainDataGenerate/blob/master/media/1.png)\u003cbr\u003e\n(2) 元画像の背景白色化 1920x1080\u003cbr\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![2.png](https://github.com/PINTO0309/YoloTrainDataGenerate/blob/master/media/2.png)\u003cbr\u003e\n(3) 物体検出 1920x1080\u003cbr\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![3.png](https://github.com/PINTO0309/YoloTrainDataGenerate/blob/master/media/3.png)\u003cbr\u003e\n(4) 背景透過処理後PNGファイル２枚 96x96\u003cbr\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![4.png](https://github.com/PINTO0309/YoloTrainDataGenerate/blob/master/media/4.png)\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![5.png](https://github.com/PINTO0309/YoloTrainDataGenerate/blob/master/media/5.png)![6.png](https://github.com/PINTO0309/YoloTrainDataGenerate/blob/master/media/6.png)\n\u003cbr\u003e\n\n# 画像の前処理\nimages_org配下のファイル名をpyrenamer等を利用して 「(ラベル名)_xxxx.png」 に一括変更\n* xxxx の箇所は同一ラベル名で重複しないように連番なり、文字列なり、自由に設定 (４桁でなくても良い)\n\n```（例）.\n　labelA_0001.png　→　「labelA」に集約\n　labelA_0002.png　→　「labelA」に集約\n　labelA_0003.png　→　「labelA」に集約\n　labelB_0001.png　→　「labelB」に集約\n　labelB_0002.png　→　「labelB」に集約\n　labelC_0001.png　→　「labelC」に集約\n　　　：\n```\n\n```（例）.ラベルがswitchとremoconの場合\n　switch_0001.png　→　「switch」に集約\n　switch_0002.png　→　「switch」に集約\n　switch_0003.png　→　「switch」に集約\n　switch_0004.png　→　「switch」に集約\n　remocon_0001.png　→　「remocon」に集約\n　remocon_0002.png　→　「remocon」に集約\n　　　：\n```\n\u003cbr\u003e\n\n# Yolo学習用画像データ他の自動生成\n\n* ランダムに回転・縮小・拡大・配置・ノイズ追加を繰り返して画像を水増し生成\n  * コントラスト変換\n  * 平滑化\n  * ヒストグラム均一化\n  * ガウシアンノイズ付加\n  * Salt\u0026Pepperノイズ付加\n  * 画像反転\n  * 画像回転\n* 任意の物体画像と任意の背景画像を自由に合成\n* 前処理で生成した連番付き画像ファイル名の連番部を無視し、複数画像をひとつのラベルへ集約\n* アノテーションを含む train.txt、test.txt、label.txt が生成される\n* images配下に水増し済みの静止画像が生成される\n* デフォルトの水増し枚数は10,000枚、変更する場合は generate_sample.py の 「train_images = 10000」 を修正する\n\n\n下記コマンドを実行\n```\n$ cd YoloTrainDataGenerate\n$ sudo chmod +x *.sh\n$ ./setup.sh\n$ python3 generate_sample.py\n```\n\u003cbr\u003e\n\u003cbr\u003e\n\u003chr\u003e\n\n# [English] YoloTrainDataGenerate\nProcedures and tools for semi-mechanically automatically generating YoloV2 original learning data from video\u003cbr\u003e\nhttps://qiita.com/PINTO/items/d5645734ca9c95b1c395\n\n　\n# Environment\n* CPU：Intel Core i7-3517U(1.9GHz)\n* MEM：16GB\n* GPU：Geforce GT 650M (VRAM:2GB)\n* OS：Ubuntu 16.04 LTS\n* OpenCV 3.4.1\n* ffmpeg\n* Samba\n* pyrenamer\n\n　\n# Rough flow\n1. Suitable movie shooting\n2. Massively generate still images mechanically from motion pictures\n3. Mechanical extraction of object parts from a large amount of still images, generation of object images through which background passes\n4. We created a background static image separately prepared and the object still image generated in 3 randomly add, rotate, reduce, enlarge, arrange, add noise and synthesize it and inflate a large amount\n\n　\n# Movie → Still image conversion\nCopy the png file generated from the movie by the following command to \"YoloTrainDataGenerate/images_org/\"\u003cbr\u003e\n`$ ffmpeg -i xxxx.mp4 -vcodec png -r 10 image_%04d.png`\n\n　\n# Multiple still image files, Machining of multiple object perimeter through mechanical processing\n* Only when the color is close to white · the object is composed only of white / gray color scheme\n* When there are multiple objects in one image, it is divided into image files for the number of objects and processed\n* Even if the input image is a rectangle, the final generated image is a 96×96 square including the object\n* For convenience of edge extraction, one overlapping object is recognized as one\n* When the area of the detected object is less than 1000px, the object is excluded from the extraction target\n* If it is determined that there is no object in the final generated image, no file is generated\n```\n$ cd YoloTrainDataGenerate\n$ python3 object_extraction.py\n```\n(1) Original image to edit 1920x1080\u003cbr\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![1.png](https://github.com/PINTO0309/YoloTrainDataGenerate/blob/master/media/1.png)\u003cbr\u003e\n(2) Background whitening of the original image 1920x1080\u003cbr\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![2.png](https://github.com/PINTO0309/YoloTrainDataGenerate/blob/master/media/2.png)\u003cbr\u003e\n(3) Object detection 1920x1080\u003cbr\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![3.png](https://github.com/PINTO0309/YoloTrainDataGenerate/blob/master/media/3.png)\u003cbr\u003e\n(4) Background PNG file after transparent processing 96x96\u003cbr\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![4.png](https://github.com/PINTO0309/YoloTrainDataGenerate/blob/master/media/4.png)\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;![5.png](https://github.com/PINTO0309/YoloTrainDataGenerate/blob/master/media/5.png)![6.png](https://github.com/PINTO0309/YoloTrainDataGenerate/blob/master/media/6.png)\n\u003cbr\u003e\n\n# Image preprocessing\nChange file name under images_org to \"(label name)_xxxx.png\" collectively using pyrenamer etc.\n* The part of xxxx is the same label name and it is a serial number so that it does not overlap, it becomes a character string, it is set freely (it does not have to be 4 digits)\n\n```(Example1)\n　labelA_0001.png　→　「labelA」Summarize\n　labelA_0002.png　→　「labelA」Summarize\n　labelA_0003.png　→　「labelA」Summarize\n　labelB_0001.png　→　「labelB」Summarize\n　labelB_0002.png　→　「labelB」Summarize\n　labelC_0001.png　→　「labelC」Summarize\n　　　：\n```\n\n```(Example2) switch and remocon\n　switch_0001.png　→　「switch」Summarize\n　switch_0002.png　→　「switch」Summarize\n　switch_0003.png　→　「switch」Summarize\n　switch_0004.png　→　「switch」Summarize\n　remocon_0001.png　→　「remocon」Summarize\n　remocon_0002.png　→　「remocon」Summarize\n　　　：\n```\n\u003cbr\u003e\n\n# Yolo image data for learning automatic generation\n\n* Repetitive rotation, reduction, enlargement, placement, and noise addition are repeated at random to create inflated images\n  * Contrast transformation\n  * Smoothing\n  * Histogram equalization\n  * Gaussian noise addition\n  * Salt \u0026 Pepper noise addition\n  * Image reversal\n  * Image rotation\n* Free combination of arbitrary object image and arbitrary background image\n* Ignoring the serial number part of the image file name with sequential number generated in preprocessing, aggregate multiple images on one label\n* Train.txt, test.txt, label.txt containing annotations are generated\n* An inflated still image is generated under images folder\n* The default number of padded sheets is 10,000, and if you change it, modify \"generate_sample.py\" train_images = 10000\n\n\nExecute the following command\n```\n$ cd YoloTrainDataGenerate\n$ sudo chmod +x *.sh\n$ ./setup.sh\n$ python3 generate_sample.py\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinto0309%2Fyolotraindatagenerate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpinto0309%2Fyolotraindatagenerate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinto0309%2Fyolotraindatagenerate/lists"}