Skip to content

hasan0v/Neuroscreen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

58 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

NeuroScreen - EtkileลŸimli Beyin-Bilgisayar Arayรผz Sistemi

๐Ÿ“– Genel BakฤฑลŸ

NeuroScreen, gerรงek zamanlฤฑ EEG sinyal analizi ile modern web teknolojilerini birleลŸtiren kapsamlฤฑ bir Beyin-Bilgisayar Arayรผz (BCI) sistemidir. Sistem, beyin sinyali izleme iรงin etkileลŸimli bir web arayรผzรผ saฤŸlar ve saฤŸlฤฑk sektรถrรผ odaklฤฑ 4 kategorili odaklanma terapisi sunar.

๐Ÿš€ ร–zellikler

๐Ÿง  EEG Sinyal ฤฐลŸleme

  • Gerรงek zamanlฤฑ EEG frekans spektrumu analizi
  • Canlฤฑ FFT gรถrselleลŸtirme ile รถzelleลŸtirilebilir frekans bantlarฤฑ
  • ร‡oklu frekans bantฤฑ izleme (Alpha, Beta, SMR, High Beta)
  • Gรผrรผltรผ filtreleme ile uyarlanabilir sinyal iลŸleme
  • Klinik seviyede beyin dalgasฤฑ simรผlasyonu

๐ŸŒ Web Arayรผzรผ

  • 4 รถzelleลŸtirilebilir saฤŸlฤฑk kategorisi (Su, Klima, Tuvalet, SOS)
  • Gerรงek zamanlฤฑ EEG spektrumu akฤฑลŸฤฑ
  • Odaklanma oturumlarฤฑ iรงin ilerleme takibi
  • Modern glassmorphism tasarฤฑm ile duyarlฤฑ arayรผz
  • Otomatik veri normalizasyonu (5 saniye hareketsizlik)
  • Tรผrkรงe dil desteฤŸi

๐Ÿ—๏ธ Proje Yapฤฑsฤฑ

neuroscreen/
โ”œโ”€โ”€ main.py                     # Flask web uygulama sunucusu
โ”œโ”€โ”€ eeg_plot.py                 # EEG sinyal iลŸleme ve gรถrselleลŸtirme
โ”œโ”€โ”€ data.txt                    # Gerรงek zamanlฤฑ veri depolama
โ”œโ”€โ”€ wsgi.py                     # รœretim WSGI giriลŸ noktasฤฑ
โ”œโ”€โ”€ config.py                   # Yapฤฑlandฤฑrma ayarlarฤฑ
โ”œโ”€โ”€ requirements.txt            # Python baฤŸฤฑmlฤฑlฤฑklarฤฑ
โ”œโ”€โ”€ Dockerfile                  # Docker container yapฤฑlandฤฑrmasฤฑ
โ”œโ”€โ”€ docker-compose.yml          # Docker Compose orchestration
โ”œโ”€โ”€ nginx.conf                  # Nginx reverse proxy yapฤฑlandฤฑrmasฤฑ
โ”œโ”€โ”€ deploy.sh                   # Linux/Mac deployment script
โ”œโ”€โ”€ deploy.bat                  # Windows deployment script
โ”œโ”€โ”€ .env.example                # ร‡evre deฤŸiลŸkeni รถrneฤŸi
โ”œโ”€โ”€ .gitignore                  # Git ignore kurallarฤฑ
โ”œโ”€โ”€ templates/                  # HTML ลŸablonlarฤฑ
โ”‚   โ”œโ”€โ”€ index.html              # Ana dashboard
โ”‚   โ””โ”€โ”€ focus.html              # Odaklanma terapisi arayรผzรผ
โ””โ”€โ”€ static/                     # Statik web varlฤฑklarฤฑ
    โ”œโ”€โ”€ css/
    โ”‚   โ””โ”€โ”€ style.css           # Stil dosyasฤฑ
    โ”œโ”€โ”€ js/
    โ”‚   โ””โ”€โ”€ app.js              # Frontend JavaScript
    โ””โ”€โ”€ images/
        โ””โ”€โ”€ logo.png            # Uygulama logosu

๐Ÿ”ง Kurulum

ร–n Gereksinimler

  • Python 3.8+
  • Modern web tarayฤฑcฤฑsฤฑ
  • Git (isteฤŸe baฤŸlฤฑ)

Hฤฑzlฤฑ BaลŸlangฤฑรง

Windows iรงin:

# Projeyi klonlayฤฑn
git clone <repository-url>
cd neuroscreen

# Deployment script'ini รงalฤฑลŸtฤฑrฤฑn
deploy.bat

Linux/Mac iรงin:

# Projeyi klonlayฤฑn
git clone <repository-url>
cd neuroscreen

# Deployment script'ini รงalฤฑลŸtฤฑrฤฑn
chmod +x deploy.sh
./deploy.sh

Manuel Kurulum:

# Sanal ortam oluลŸturun
python -m venv venv

# Sanal ortamฤฑ etkinleลŸtirin
# Windows: venv\Scripts\activate
# Linux/Mac: source venv/bin/activate

# BaฤŸฤฑmlฤฑlฤฑklarฤฑ yรผkleyin
pip install -r requirements.txt

# Uygulamayฤฑ baลŸlatฤฑn
python main.py

๐Ÿš€ รœretim DaฤŸฤฑtฤฑmฤฑ

1. Basit รœretim (Waitress/Gunicorn)

Windows:

start_production.bat

Linux/Mac:

./start_production.sh

2. Docker ile DaฤŸฤฑtฤฑm

# Docker container oluลŸturun
docker build -t neuroscreen .

# Container'ฤฑ รงalฤฑลŸtฤฑrฤฑn
docker run -d -p 5000:5000 neuroscreen

3. Docker Compose ile Tam YฤฑฤŸฤฑn

# Tรผm servisleri baลŸlatฤฑn (Nginx + NeuroScreen)
docker-compose up -d

# Loglarฤฑ gรถrรผntรผleyin
docker-compose logs -f

4. Nginx Reverse Proxy

Nginx yapฤฑlandฤฑrmasฤฑ dahil edilmiลŸtir:

  • Statik dosya รถnbellekleme
  • Gzip sฤฑkฤฑลŸtฤฑrma
  • Rate limiting
  • SSL/TLS desteฤŸi (yapฤฑlandฤฑrma gerekli)

๐Ÿ“Š Sistem BileลŸenleri

1. EEG Sinyal ฤฐลŸleme (eeg_plot.py)

  • ร–rnekleme Hฤฑzฤฑ: 256 Hz
  • Frekans Bantlarฤฑ:
    • Alpha dalgalarฤฑ: 8-13 Hz (rahatlatฤฑcฤฑ odaklanma)
    • SMR: 12-15 Hz (sensorimotor ritim)
    • Beta dalgalarฤฑ: 14-30 Hz (aktif odaklanma)
    • High Beta: 30+ Hz (yรผksek uyarฤฑlma)
  • Sinyal รœretimi: Klinik seviyede gerรงekรงi EEG simรผlasyonu
  • GรถrselleลŸtirme: Gerรงek zamanlฤฑ dual-plot (zaman + frekans)

2. Web Arayรผzรผ

  • Backend: Flask REST API
  • Frontend: Vanilla JavaScript + CSS3 Glassmorphism
  • Gerรงek Zamanlฤฑ ฤฐletiลŸim: Server-Sent Events
  • Veri Depolama: Dosya tabanlฤฑ JSON depolama

3. SaฤŸlฤฑk Kategori Sistemi

  • Su: Hidrasyon hatฤฑrlatฤฑcฤฑsฤฑ (mavi tema)
  • Klima: Hava koลŸullarฤฑ kontrolรผ (aรงฤฑk mavi tema)
  • Tuvalet: Mola hatฤฑrlatฤฑcฤฑsฤฑ (sarฤฑ tema)
  • SOS: Acil durum sinyali (kฤฑrmฤฑzฤฑ tema)

๐Ÿ”ฌ Teknik Detaylar

EEG Sinyal Haritalama

frequency_mapping = {
    "first": {"freq": 10, "name": "Alpha (Relaxed Focus)"},     # Su
    "second": {"freq": 18, "name": "SMR (Sensory Motor)"},     # Klima
    "third": {"freq": 24, "name": "Beta (Active Focus)"},      # Tuvalet
    "fifth": {"freq": 30, "name": "High Beta (Alert)"}         # SOS
}

Otomatik Normalizasyon

  • 5 saniye hareketsizlik sonrasฤฑ otomatik sฤฑfฤฑrlama
  • Fare hareketi, klavye aktivitesi ve dokunma algฤฑlama
  • Sessiz arka plan normalizasyonu

Glassmorphism Tasarฤฑm

  • Modern backdrop-filter efektleri
  • Animasyonlu gradyan arka planlar
  • Responsive 2x2 grid layout
  • GeliลŸmiลŸ hover efektleri

๐Ÿ“ฑ API Uรง Noktalarฤฑ

Uรง Nokta Metod Aรงฤฑklama
/ GET Ana dashboard
/focus GET Odaklanma terapisi arayรผzรผ
/eeg_stream GET Gerรงek zamanlฤฑ EEG akฤฑลŸฤฑ
/get_data GET Mevcut veriyi al
/push_data POST Veri deฤŸerlerini gรผncelle
/reset_data GET Veriyi varsayฤฑlana sฤฑfฤฑrla

Veri Formatฤฑ

{
    "first": 0,     // Su kategorisi aktivasyonu (0/1)
    "second": 0,    // Klima kategorisi aktivasyonu (0/1)
    "third": 0,     // Tuvalet kategorisi aktivasyonu (0/1)
    "fifth": 0      // SOS kategorisi aktivasyonu (0/1)
}

๐ŸŽฏ Odaklanma EฤŸitim Sistemi

EtkileลŸim Yรถntemleri

  • Fare Hover: 5 saniye hover ile kategori aktivasyonu
  • ฤฐlerleme GรถrselleลŸtirme: Gerรงek zamanlฤฑ ilerleme รงubuklarฤฑ
  • Gรถrsel Geri Bildirim: BaลŸarฤฑ/hata bildirimleri

Otomatik ร–zellikler

  • Hareketsizlik Algฤฑlama: 5 saniye sonra otomatik normalizasyon
  • Oturum Takibi: Gerรงek zamanlฤฑ oturum sรผresi
  • Sistem Durumu: Canlฤฑ sistem durumu gรถstergesi

๐Ÿ”ง Yapฤฑlandฤฑrma

ร‡evre DeฤŸiลŸkenleri

# .env dosyasฤฑ oluลŸturun (.env.example'dan kopyalayฤฑn)
cp .env.example .env

# รœretim iรงin รถnemli ayarlar
SECRET_KEY=your-super-secret-key
FLASK_ENV=production
HOST=0.0.0.0
PORT=5000

EEG Parametreleri

fs = 256                    # ร–rnekleme frekansฤฑ (Hz)
window_size = 4             # Sinyal penceresi (saniye)
noise_level = 3             # Arka plan gรผrรผltรผsรผ
transition_duration = 3.0   # GeรงiลŸ sรผresi (saniye)

Gรผvenlik Ayarlarฤฑ

  • CSRF korumasฤฑ
  • XSS korumasฤฑ
  • Content Security Policy
  • Rate limiting (Nginx ile)
  • HTTPS yรถnlendirmesi

๐Ÿ” Sorun Giderme

Yaygฤฑn Sorunlar

  1. EEG akฤฑลŸฤฑ yรผklenmiyor:

    • Flask sunucusunun รงalฤฑลŸtฤฑฤŸฤฑnฤฑ doฤŸrulayฤฑn
    • Tarayฤฑcฤฑ konsolunda hatalarฤฑ kontrol edin
    • data.txt dosyasฤฑnฤฑn var olduฤŸunu ve okunabilir olduฤŸunu kontrol edin
  2. BaฤŸฤฑmlฤฑlฤฑk hatalarฤฑ:

    • Python versiyonunu kontrol edin (3.8+)
    • Sanal ortamฤฑn etkin olduฤŸunu doฤŸrulayฤฑn
    • requirements.txt'yi yeniden yรผkleyin
  3. Port kullanฤฑmda hatasฤฑ:

    • Farklฤฑ port kullanฤฑn: python main.py --port 8000
    • Mevcut Python iลŸlemlerini durdurun
  4. Static dosyalar yรผklenmiyor:

    • Static klasรถr yapฤฑsฤฑnฤฑ kontrol edin
    • Nginx yapฤฑlandฤฑrmasฤฑnฤฑ doฤŸrulayฤฑn
    • Dosya izinlerini kontrol edin

Log Dosyalarฤฑ

# Uygulama loglarฤฑ
tail -f logs/neuroscreen.log

# Nginx loglarฤฑ (Docker ile)
docker-compose logs nginx

# Container loglarฤฑ
docker logs <container-name>

๐Ÿš€ Performans Optimizasyonu

รœretim Ayarlarฤฑ

  • Gunicorn Workers: 4 worker (varsayฤฑlan)
  • Timeout: 120 saniye
  • Static File Caching: 1 saat
  • Gzip Compression: Etkin
  • Rate Limiting: API iรงin 10 req/s

Monitoring

  • Health check endpoints
  • Application metrics
  • Resource usage monitoring
  • Error tracking

๐Ÿ”ฎ Gelecek GeliลŸtirmeler

  • Gerรงek EEG donanฤฑm entegrasyonu (OpenBCI, NeuroSky)
  • Makine รถฤŸrenmesi tabanlฤฑ sinyal sฤฑnฤฑflandฤฑrmasฤฑ
  • ร‡oklu kullanฤฑcฤฑ oturum yรถnetimi
  • GeliลŸmiลŸ gรถrselleลŸtirme seรงenekleri
  • Mobil uygulama desteฤŸi
  • Bulut veri senkronizasyonu
  • Ses komut entegrasyonu
  • Biometrik kimlik doฤŸrulama

๐Ÿค Katkฤฑda Bulunma

  1. Repository'yi fork edin
  2. Feature branch oluลŸturun
  3. DeฤŸiลŸikliklerinizi commit edin
  4. Branch'inizi push edin
  5. Pull Request oluลŸturun

๐Ÿ“„ Lisans

Bu proje aรงฤฑk kaynaklฤฑdฤฑr ve MIT Lisansฤฑ altฤฑnda mevcuttur.

๐Ÿ†˜ Destek

Destek ve sorular iรงin:

  • Repository'de issue oluลŸturun
  • Sorun giderme bรถlรผmรผnรผ kontrol edin
  • Teknik dokรผmantasyonu inceleyin

๐Ÿ™ TeลŸekkรผrler

  • Flask ekibi web framework iรงin
  • NumPy ve Matplotlib bilimsel hesaplama iรงin
  • Modern web teknolojileri topluluฤŸu
  • Aรงฤฑk kaynak katkฤฑcฤฑlarฤฑ

Not: Bu sistem araลŸtฤฑrma ve eฤŸitim amaรงlarฤฑna yรถneliktir. Tฤฑbbi uygulamalar iรงin saฤŸlฤฑk uzmanlarฤฑ ile gรถrรผลŸรผn ve ilgili dรผzenlemelere uygunluฤŸu saฤŸlayฤฑn.

๐Ÿ“Š System Components

1. EEG Signal Processing (eeg_plot.py)

  • Sampling Rate: 256 Hz
  • Frequency Bands:
    • Alpha waves: 14 Hz
    • Beta waves: 21-33 Hz range
  • Signal Generation: Synthetic EEG with configurable amplitude and noise
  • Visualization: Real-time FFT spectrum (0-40 Hz range)

2. Eye Tracking System (eye tracker/)

  • Face Detection: MediaPipe Face Mesh with 468 landmarks
  • Iris Tracking: Precise iris center calculation
  • Calibration: Multi-point polynomial regression (order 2)
  • Filtering: Kalman filter for smooth tracking
  • Accuracy: Sub-pixel precision with noise reduction

3. Web Interface

  • Backend: Flask REST API
  • Frontend: Vanilla JavaScript with CSS3
  • Real-time Communication: Server-Sent Events for EEG streaming
  • Data Storage: File-based JSON storage

๐Ÿš€ Usage

Starting the Web Application

  1. Launch the Flask server:

    python main.py

    The server will start on http://localhost:5000

  2. Access the dashboard:

    • Navigate to http://localhost:5000 for EEG monitoring
    • Navigate to http://localhost:5000/focus for focus training

Eye Tracking Application

  1. Run the eye tracker:

    cd "eye tracker"
    python main.py
  2. Calibration Process:

    • Press c to start calibration
    • Follow the calibration points (look at each point for 0.8 seconds)
    • System will automatically complete calibration
  3. Controls:

    • c: Start calibration
    • v: Toggle camera view
    • r: Reset system
    • q: Quit application

๐Ÿ”ฌ Technical Details

EEG Signal Mapping

frequency_mapping = {
    "first": 21,    # Focus Zone 1
    "second": 24,   # Focus Zone 2  
    "third": 27,    # Focus Zone 3
    "fourth": 30,   # Focus Zone 4
    "fifth": 33,    # Focus Zone 5
    "sixth": 14     # Relaxation Zone
}

Eye Tracking Features

  • Landmark Extraction: 468 facial landmarks
  • Iris Points: 4-point iris detection per eye
  • Normalization: Eye-relative coordinate system
  • Bilateral Processing: Combined left and right eye data

Calibration Algorithm

# Polynomial feature expansion for improved accuracy
def poly_features(fx, fy, order=2):
    if order == 2:
        return [1, fx, fy, fx*fx, fy*fy, fx*fy]
    return [1, fx, fy]

๐Ÿ“ฑ API Endpoints

Flask Web API

Endpoint Method Description
/ GET Main dashboard
/focus GET Focus training interface
/eeg_stream GET Real-time EEG stream
/get_data GET Retrieve current data
/push_data POST Update data values
/reset_data GET Reset data to defaults

Data Format

{
    "first": 0,     // Zone 1 activation (0/1)
    "second": 0,    // Zone 2 activation (0/1)
    "third": 0,     // Zone 3 activation (0/1)
    "fourth": 0,    // Zone 4 activation (0/1)
    "fifth": 0,     // Zone 5 activation (0/1)
    "sixth": 0      // Zone 6 activation (0/1)
}

๐ŸŽฏ Focus Training System

Zone Configuration

The system divides the screen into 6 interactive zones:

  1. Water (Yellow) - Hydration reminder
  2. Food (Red) - Nutrition reminder
  3. Medicine (Yellow) - Medication reminder
  4. Images (Blue) - Visual content
  5. Toilet (Pink) - Break reminder
  6. Other (Green) - Miscellaneous actions

Interaction Methods

  • Mouse Hover: 5-second hover triggers zone activation
  • Eye Gaze: 5-second sustained gaze triggers activation
  • Progress Visualization: Real-time progress bars

๐Ÿ”ง Configuration

Screen Resolution Setup

# Automatic detection
SCREEN_W = root.winfo_screenwidth()
SCREEN_H = root.winfo_screenheight()

# Manual configuration (if needed)
SCREEN_W, SCREEN_H = 1920, 1080

EEG Parameters

fs = 256  # Sampling frequency (Hz)
window_size = 10  # Signal window (seconds)
noise_level = 5   # Background noise amplitude

Eye Tracking Sensitivity

min_detection_confidence = 0.5
min_tracking_confidence = 0.5
kalman_process_noise = 0.03

๐Ÿ” Troubleshooting

Common Issues

  1. Camera not detected:

    • Check camera permissions
    • Try different camera indices (0, 1, 2...)
    • Ensure no other application is using the camera
  2. EEG stream not loading:

    • Verify Flask server is running
    • Check browser console for errors
    • Ensure data.txt file exists and is readable
  3. Calibration failure:

    • Ensure good lighting conditions
    • Keep face centered and stable
    • Maintain consistent distance from camera
  4. Poor tracking accuracy:

    • Recalibrate the system
    • Check camera focus and resolution
    • Ensure minimal head movement

๐Ÿ”ฎ Future Enhancements

  • Real EEG hardware integration (OpenBCI, NeuroSky)
  • Machine learning-based signal classification
  • Multi-user session management
  • Advanced visualization options
  • Mobile application support
  • Cloud data synchronization
  • Voice command integration
  • Biometric authentication

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

๐Ÿ“„ License

This project is open source and available under the MIT License.

๐Ÿ†˜ Support

For support and questions:

  • Create an issue in the repository
  • Check the troubleshooting section
  • Review the technical documentation

๐Ÿ™ Acknowledgments

  • MediaPipe team for facial landmark detection
  • OpenCV community for computer vision tools
  • Flask team for the web framework
  • NumPy and Matplotlib for scientific computing

Note: This system is designed for research and educational purposes. For medical applications, please consult with healthcare professionals and ensure compliance with relevant regulations.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors