🧠 ブレインマシンインターフェース
脳波データとビジョン情報を統合した未来的インターフェース
import cv2 import numpy as np import time class SimpleBMISimulator: """簡易BMIシミュレーター"""
def __init__(self): self.attention_level = 0.5 self.focus_point = (320,
240) def simulate_brain_signals(self): """脳波信号をシミュレート"""
# 実際のBMIでは脳波計からデータを取得 alpha = np.random.normal(0.3, 0.1) # リラックス beta =
np.random.normal(0.4, 0.15) # 集中 gamma = np.random.normal(0.1, 0.05) #
高次認知 # 注意レベルを計算 self.attention_level = max(0, min(1, (beta + gamma) / 2))
return { 'alpha': max(0, alpha), 'beta': max(0, beta), 'gamma': max(0,
gamma), 'attention': self.attention_level } def apply_mental_state_to_vision(self,
frame, brain_data): """精神状態に基づいて映像を変化"""
h, w = frame.shape[:2] # 集中度に応じてズーム if brain_data['attention'] > 0.7:
zoom_factor = 1 + (brain_data['attention'] - 0.7) * 2 center_x, center_y
= w//2, h//2 crop_size = int(min(w, h) / zoom_factor) x1 = max(0, center_x
- crop_size//2) y1 = max(0, center_y - crop_size//2) x2 = min(w, x1 + crop_size)
y2 = min(h, y1 + crop_size) cropped = frame[y1:y2, x1:x2] frame = cv2.resize(cropped,
(w, h)) # リラックス度に応じてぼかし if brain_data['alpha'] > 0.5: blur_strength
= int(brain_data['alpha'] * 20) if blur_strength % 2 == 0: blur_strength
+= 1 frame = cv2.GaussianBlur(frame, (blur_strength, blur_strength), 0)
# 注意レベル表示 bar_width = int(200 * brain_data['attention']) cv2.rectangle(frame,
(20, 20), (220, 40), (100, 100, 100), 2) cv2.rectangle(frame, (20, 20),
(20 + bar_width, 40), (0, 255, 0), -1) cv2.putText(frame, f'Attention:
{brain_data["attention"]:.2f}', (20, 15), cv2.FONT_HERSHEY_SIMPLEX,
0.5, (255, 255, 255), 1) return frame # BMIシミュレーション実行 bmi = SimpleBMISimulator()
cap = cv2.VideoCapture(0) print("BMI ビジョンシステム開始") print("-
集中すると画像がズーム") print("- リラックスするとぼかし効果") while True: ret,
frame = cap.read() if not ret: break # 脳波データをシミュレート brain_data = bmi.simulate_brain_signals()
# 精神状態を映像に反映 processed_frame = bmi.apply_mental_state_to_vision(frame,
brain_data) cv2.imshow('BMI Vision Interface', processed_frame) if cv2.waitKey(1)
& 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()