軸受欠陥検出の技術的課題
産業機械の要部である軸受は、溝状欠陥・凹み・擦過傷・ひっかき傷などの表面損傷が発生すると装置の信頼性が低下します。従来の目視検査は主観的で再現性が低く、画像処理ベースの手法は複雑な照明条件に弱いという課題があります。本システムでは、Ultralytics社の最新アルゴリズムを拡張したYOLOv12を活用し、産業現場に即応するリアルタイム検出を実現しました。
システム機能の詳細
- マルチモーダル検出:画像ファイル(JPG/PNG)、動画ストリーム(MP4/AVI)、リアルタイムカメラ入力に対応
- 二重表示インターフェース:左側に生画像、右側に検出結果を並列表示
- 動的パラメータ調整:信頼度閾値(0.0-1.0)とIoU閾値をスライダーで即時反映
- セキュアなユーザ管理:6文字以上のパスワード要件を満たすローカル認証システム
データセット構成
4種類の軸受表面欠陥を含む1,085枚のアノテーション済み画像を使用:
- 訓練データ:759枚(溝状欠陥/groove、凹み/dent、擦過傷/scratch、ひっかき傷/abrasion)
- 検証データ:326枚
データセット設定ファイル(data.yaml):
train: ./dataset/images/train
val: ./dataset/images/val
nc: 4
names: ['groove', 'dent', 'scratch', 'abrasion']
環境構築手順
Conda仮想環境の作成:
conda create -n bearing-detection python=3.9
conda activate bearing-detection
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
必須ライブラリのインストール:
pip install -r requirements.txt
モデル学習の実装
学習スクリプト(train_bearing.py):
from ultralytics import DefectModel
if __name__ == "__main__":
model = DefectModel('yolo12m.pt')
model.train(
data='data.yaml',
epochs=100,
batch_size=8,
device='cpu',
workers=2,
project='bearing_detection'
)
モデル選択ガイド:
- yolo12n:組み込み機器向け軽量版(推論速度重視)
- yolo12s:リアルタイム処理向けバランス型
- yolo12m:汎用検出タスク向け標準モデル
コアコンポーネントの実装
検出処理スレッド(DefectDetectionThread.py):
class DefectDetectionThread(QThread):
detection_signal = pyqtSignal(QImage, QImage, list)
def __init__(self, model, source, confidence_threshold, iou_threshold):
super().__init__()
self.detector = model
self.input_source = source
self.conf_thresh = confidence_threshold
self.iou_thresh = iou_threshold
self.active = True
def run(self):
capture = cv2.VideoCapture(self.input_source)
while self.active and capture.isOpened():
ret, frame = capture.read()
if not ret: break
original = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
results = self.detector.predict(
frame,
conf=self.conf_thresh,
iou=self.iou_thresh
)
annotated = results[0].visualize()
defects = []
for obj in results[0].objects:
defects.append((
obj.class_name,
round(obj.confidence, 2),
int(obj.bbox.x),
int(obj.bbox.y)
))
self.detection_signal.emit(
self.convert_to_qimage(original),
self.convert_to_qimage(annotated),
defects
)
QThread.msleep(30)
ユーザ認証モジュール(AuthManager.py):
def validate_credentials(username, password):
if not os.path.exists('user_data.json'):
return False
with open('user_data.json', 'r') as f:
users = json.load(f)
if username in users:
return check_password_hash(users[username]['hash'], password)
return False
def register_user(username, password):
if len(password) < 6:
return "パスワードは6文字以上必要です"
# ハッシュ化処理を実装
UIインタフェース設計
検出結果表示テーブルの実装:
def update_result_table(self, defects):
self.result_table.setRowCount(len(defects))
for row, (cls, conf, x, y) in enumerate(defects):
self.result_table.setItem(row, 0, QTableWidgetItem(cls))
self.result_table.setItem(row, 1, QTableWidgetItem(f"{conf:.2f}"))
self.result_table.setItem(row, 2, QTableWidgetItem(str(x)))
self.result_table.setItem(row, 3, QTableWidgetItem(str(y)))
リアルタイム状態表示バー:
def update_status(self, message):
current_time = QTime.currentTime().toString("HH:mm:ss")
self.status_bar.showMessage(
f"処理状況: {message} | 最終更新: {current_time}"
)