Project
中文
PCB 標註工具(PCB Annotator)是一個以 Tkinter + OpenCV + Pillow 實作的桌面標註小工具。可在 PCB 圖片上以矩形標記缺陷(例如缺焊、短路等),拖曳時即時顯示缺陷文字,並能匯出標記後圖片與 CSV(UTF‑8‑SIG)。
English
PCB Annotator is a lightweight desktop tool built with Tkinter + OpenCV + Pillow. Draw rectangular annotations on PCB images (e.g., missing solder, short), show defect labels live while drawing, and export annotated images and CSV files (UTF‑8‑SIG).
Features 中文
拖曳建立矩形標記並即時顯示缺陷文字。
選取、刪除、重製標記;下拉式清單顯示所有標記。
儲存標記後圖片到 marked/,圖片中文字由 Pillow 繪製以支援中文。
匯出 CSV 到 csv/,使用 UTF‑8‑SIG 編碼;若選擇既有 CSV,會以 append 方式補上資料。
相容 Pillow 10+(使用 font.getbbox 取得文字尺寸),並提供字型 fallback。
English
Draw rectangular annotations by dragging; defect label shown live while drawing.
Select, delete, reset annotations; dropdown lists all annotations.
Save annotated image to marked/ with Chinese labels rendered via Pillow.
Export CSV to csv/ encoded as UTF‑8‑SIG; choosing an existing CSV appends rows.
Compatible with Pillow 10+ and includes font fallback handling.
Installation 中文
安裝 Python 3.8 或更新版本。
安裝必要套件 pip install opencv-python pillow numpy
將中文字型放到專案資料夾下的 font/msjh.ttc,或修改程式中 ImageFont.truetype 的路徑指向你系統上的字型檔。
執行程式: python marking_tool.py
Place a Chinese font at font/msjh.ttc in the project folder or update the font path in the code.
Run the tool: python marking_tool.py
Usage 中文
點選 載入 PCB 圖片 選擇影像。
在畫面上按下並拖曳以建立標記;拖曳時會顯示黃色暫時框與缺陷文字,放開後成為紅色正式標記並保留文字。
使用缺陷類型下拉選單選擇標籤內容(例如缺焊、短路)。
點 儲存標記:會產生 marked/_marked.jpg(含中文文字)並提示儲存 CSV;若選擇既有 CSV,會以 append 方式加入新列;若取消選擇,會自動建立 csv/
.csv。
CSV 欄位:image_path, defect_type, bbox_x, bbox_y, bbox_w, bbox_h, is_defective。
English
Click Load PCB Image to open an image.
Click and drag on the canvas to create an annotation; a yellow temporary box and defect label appear while dragging. Release to finalize the annotation (red box).
Choose defect type from the dropdown (e.g., Missing Solder, Short).
Click Save Markings to save an annotated image to marked/_marked.jpg and export CSV. If you pick an existing CSV file, new rows are appended; if you cancel, the tool writes to csv/
.csv.
CSV columns: image_path, defect_type, bbox_x, bbox_y, bbox_w, bbox_h, is_defective.
License
中文
本專案採用 MIT 授權。你可以自由使用、修改、散布本程式碼,但需保留原始授權聲明與版權宣告。請將下方 [YEAR] 與 [COPYRIGHT HOLDER] 替換為實際年份與你的名稱或公司名稱。
English
This project is licensed under the MIT License. You are free to use, modify, and distribute the code, provided that the copyright and license notice are included. Replace [YEAR] and [COPYRIGHT HOLDER] below with the actual year and your name or organization.
MIT License
Copyright (c) [YEAR] [COPYRIGHT HOLDER]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.