Skip to content

Latest commit

Β 

History

40 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Four Heavenly Principle

πŸ›οΈ Sistem Terpadu Manajemen RW dengan AI-Powered Fraud Detection

Project Based Learning - Politeknik Negeri Malang

Modernisasi Administrasi Rukun Warga melalui Teknologi Digital

πŸ“– About β€’ πŸš€ Installation β€’ πŸ“š Full Docs β€’ πŸ’­ Reflection


πŸ“‹ Daftar Isi

Dokumentasi Umum

Dokumentasi Per Sub-Project

Laporan Reflektif


🎯 Tentang Project

Four Heavenly Principle adalah ekosistem aplikasi terintegrasi yang dikembangkan untuk modernisasi sistem administrasi RW (Rukun Warga). Project ini menggabungkan tiga komponen utama yang saling terintegrasi:

πŸ”· Tiga Pilar Utama

1. Machine Learning πŸ€–

Sistem deteksi fraud KTP berbasis Deep Learning:

  • Fraud Detection Model: CNN (Convolutional Neural Network) untuk deteksi tampering KTP
  • Dataset & Training: Terorganisir dengan folder train/, test/, val/ untuk orientasi 0Β°, 90Β°, 180Β°, 270Β°
  • Model Artifacts:
    • ktp_fraud_cnn_tampering_v1.h5 - Model Keras/TensorFlow
    • ktp_fraud_cnn_tampering_v1.tflite - Optimized model untuk deployment mobile
  • API Integration: Folder ktpfraud_api untuk REST API endpoint
  • Notebook Development: coba.ipynb dan tes.ipynb untuk eksperimen & prototyping
  • Accuracy: 90.5%+ fraud detection rate

2. PCVK (Pengolahan Citra Visi & Komputer) πŸ“·

Library computer vision untuk OCR digit recognition KTP:

  • SVM Classifier: Pre-trained model digit_svm_best_ml.xml untuk klasifikasi digit 0-9
  • Feature Engineering: Konfigurasi HOG features dalam digit_feature_config.json
  • Training Dataset: Folder Numbers/ berisi dataset terstruktur untuk setiap digit (0-9)
  • OCR Notebook: ocr_ktp.ipynb untuk development & testing pipeline OCR
  • Image Processing: Preprocessing dengan OpenCV (grayscale, denoising, binarization, HOG)
  • Pipeline: Image preprocessing β†’ Digit segmentation β†’ Feature extraction β†’ SVM classification
  • Performance: Accuracy 93.5% dengan inference time <20ms per digit

3. Pentagram (Jawara Pintar) πŸ“±

Aplikasi mobile cross-platform Flutter dengan arsitektur lengkap:

  • Core Features:
    • Dashboard dengan analytics real-time
    • Manajemen warga (citizen management) dengan family mutation tracking
    • Sistem keuangan RW (finance models & transactions)
    • Broadcast & activity management
    • Chat & messaging system antar warga
    • Penerimaan warga baru dengan KTP verification
    • Log aktivitas & audit trail lengkap
    • Channel transfer & notifikasi
    • User profile management
  • Tech Stack:
    • Flutter SDK 3.8.1+
    • State Management: Riverpod (^2.3.6)
    • Firebase Services: Auth, Firestore, Realtime Database, Messaging (FCM)
    • Camera & Image Picker untuk KTP capture
    • Charts & Analytics: fl_chart
  • Arsitektur Bersih:
    • Models: 17+ data models (citizen, family, transaction, activity, dll)
    • Services: 17+ service layers untuk business logic
    • Pages: Organized per feature (dashboard/, keuangan/, broadcast/, chat/, dll)
    • Providers: State management dengan Riverpod
    • Repositories: Data access layer
  • Multi-Platform: Android, iOS, Web, Windows, Linux, macOS support
  • Firebase Integration: Authentication, Cloud Storage, Push Notifications (FCM)

🌟 Keunggulan Sistem

Terintegrasi & Otomatis

  • OCR KTP Otomatis: Ekstraksi data (NIK, nama, alamat) dari foto KTP
  • Fraud Detection AI: Deteksi tampering/manipulasi KTP dengan CNN
  • Auto-verification: Data warga otomatis terverifikasi melalui ML pipeline
  • Real-time synchronization antar device
  • Automated fraud detection & data extraction

Modern & User-Friendly

  • Material Design 3 interface
  • Intuitive navigation
  • Responsive design (mobile, tablet, web)

Secure & Reliable

  • Role-based access control
  • Firebase authentication
  • Audit trail lengkap (log aktivitas)

Scalable & Cloud-Based

  • Firebase infrastructure
  • No need for local servers
  • Easy to scale

πŸ—οΈ Arsitektur Sistem Keseluruhan

High-Level System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                                                    β”‚
β”‚                     PENGGUNA (End Users)                           β”‚
β”‚            (Admin RW, Ketua RW, Bendahara, Warga)                  β”‚
β”‚                                                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
                           β”‚ Mobile App / Web Browser
                           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                                                    β”‚
β”‚                   PENTAGRAM MOBILE APP                             β”‚
β”‚                    (Flutter Framework)                             β”‚
β”‚                                                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β”‚
β”‚  β”‚  Dashboard  β”‚  β”‚  Manajemen  β”‚  β”‚   Keuangan   β”‚                β”‚
β”‚  β”‚  Analytics  β”‚  β”‚    Warga    β”‚  β”‚      RW      β”‚                β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                β”‚
β”‚                                                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β”‚
β”‚  β”‚  Broadcast  β”‚  β”‚    Pesan    β”‚  β”‚     Log      β”‚                β”‚
β”‚  β”‚  & Kegiatan β”‚  β”‚    Warga    β”‚  β”‚  Aktivitas   β”‚                β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                β”‚
β”‚                                                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                                    β”‚
       β”‚ Firebase SDK                       β”‚ HTTPS API Call
       β”‚                                    β”‚
       β–Ό                                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   FIREBASE SERVICES      β”‚      β”‚    EXTERNAL ML API              β”‚
β”‚                          β”‚      β”‚                                 β”‚
β”‚  β€’ Authentication        β”‚      β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β€’ Cloud Firestore       β”‚      β”‚  β”‚   Flask Application      β”‚   β”‚
β”‚  β€’ Realtime Database     │◄──────  β”‚   (Python Backend)       β”‚   β”‚
β”‚  β€’ Cloud Storage         β”‚      β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β€’ Cloud Messaging (FCM) β”‚      β”‚             β”‚                   β”‚
β”‚  β€’ Hosting (Web)         β”‚      β”‚             β–Ό                   β”‚
β”‚                          β”‚      β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚  β”‚  TFLite Model Inference  β”‚   β”‚
                                  β”‚  β”‚  (CNN Fraud Detection)   β”‚   β”‚
                                  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
                                  β”‚             β”‚                   β”‚
                                  β”‚             β–Ό                   β”‚
                                  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
                                  β”‚  β”‚   PCVK Preprocessing     β”‚   β”‚
                                  β”‚  β”‚   (OpenCV + HOG + SVM)   β”‚   β”‚
                                  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
                                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow - Verifikasi KTP Workflow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  1. USER ACTION                                                 β”‚
β”‚     Warga upload foto KTP melalui Pentagram App                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  2. IMAGE PREPROCESSING (Client-side)                           β”‚
β”‚     β€’ Resize to standard size                                   β”‚
β”‚     β€’ Basic validation (file type, size)                        β”‚
β”‚     β€’ Convert to appropriate format                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  3. SEND TO ML API                                              β”‚
β”‚     POST https://ml-api.com/predict                             β”‚
β”‚     Content-Type: multipart/form-data                           β”‚
β”‚     Body: { file: <image_data> }                                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  4. PCVK PREPROCESSING (Server-side)                            β”‚
β”‚     β€’ Grayscale conversion                                      β”‚
β”‚     β€’ Noise reduction (Gaussian blur)                           β”‚
β”‚     β€’ Binarization (Otsu's thresholding)                        β”‚
β”‚     β€’ Morphological operations                                  β”‚
β”‚     β€’ Image enhancement (CLAHE)                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  5. ML MODEL INFERENCE                                          β”‚
β”‚     β€’ Load preprocessed image                                   β”‚
β”‚     β€’ Run through CNN model (TFLite)                            β”‚
β”‚     β€’ Output: Probability scores                                β”‚
β”‚       - P(VALID) = 0.92                                         β”‚
β”‚       - P(FRAUD) = 0.08                                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  6. DECISION MAKING                                             β”‚
β”‚     IF P(VALID) >= 0.5:                                         β”‚
β”‚         label = "VALID"                                         β”‚
β”‚         β†’ Proceed with OCR extraction (PCVK)                    β”‚
β”‚     ELSE:                                                       β”‚
β”‚         label = "FRAUD"                                         β”‚
β”‚         β†’ Reject and notify                                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  6B. OCR DATA EXTRACTION (If VALID)                             β”‚
β”‚     β€’ Digit segmentation (ROI detection)                        β”‚
β”‚     β€’ HOG feature extraction per digit                          β”‚
β”‚     β€’ SVM classification (0-9)                                  β”‚
β”‚     β€’ NIK reconstruction from digits                            β”‚
β”‚     β€’ Confidence score validation                               β”‚
β”‚     Output: {NIK: "3201234567890123", confidence: 0.95}         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  7. RESPONSE TO APP                                             β”‚
β”‚     {                                                           β”‚
β”‚       "label": "VALID",                                         β”‚
β”‚       "p_valid": 0.92,                                          β”‚
β”‚       "p_fraud": 0.08,                                          β”‚
β”‚       "threshold": 0.5                                          β”‚
β”‚     }                                                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  8. SAVE TO FIREBASE                                            β”‚
β”‚     IF VALID:                                                   β”‚
β”‚       β€’ Save KTP image to Firebase Storage                      β”‚
β”‚       β€’ Create/Update user document in Firestore                β”‚
β”‚       β€’ Set verification status = "verified"                    β”‚
β”‚       β€’ Log activity to audit trail                             β”‚
β”‚     IF FRAUD:                                                   β”‚
β”‚       β€’ Log fraud attempt                                       β”‚
β”‚       β€’ Notify admin                                            β”‚
β”‚       β€’ Set verification status = "rejected"                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  9. UI UPDATE                                                   β”‚
β”‚     β€’ Show success/error message to user                        β”‚
β”‚     β€’ Update UI with verification status                        β”‚
β”‚     β€’ Enable/disable next steps based on result                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Component Integration Diagram

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Pentagram App      β”‚
                    β”‚   (Flutter/Dart)     β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚              β”‚              β”‚
                β–Ό              β–Ό              β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚ Firebase β”‚   β”‚ ML API   β”‚   β”‚  Local   β”‚
        β”‚ Services β”‚   β”‚ (Flask)  β”‚   β”‚ Storage  β”‚
        β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚              β”‚
             β”‚              β–Ό
             β”‚      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
             β”‚      β”‚  Machine Learning     β”‚
             β”‚      β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
             β”‚      β”‚  β”‚  TFLite Model   β”‚  β”‚
             β”‚      β”‚  β”‚  (CNN Fraud     β”‚  β”‚
             β”‚      β”‚  β”‚   Detection)    β”‚  β”‚
             β”‚      β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
             β”‚      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚                  β”‚
             β”‚                  β–Ό
             β”‚      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
             β”‚      β”‚        PCVK           β”‚
             β”‚      β”‚  (CV + OCR System)    β”‚
             β”‚      β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
             β”‚      β”‚  β”‚ Image Preproc.  β”‚  β”‚
             β”‚      β”‚  β”‚ (OpenCV)        β”‚  β”‚
             β”‚      β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
             β”‚      β”‚           β”‚           β”‚
             β”‚      β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
             β”‚      β”‚  β”‚ HOG Feature     β”‚  β”‚
             β”‚      β”‚  β”‚ Extraction      β”‚  β”‚
             β”‚      β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
             β”‚      β”‚           β”‚           β”‚
             β”‚      β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
             β”‚      β”‚  β”‚ SVM Classifier  β”‚  β”‚
             β”‚      β”‚  β”‚ (digit_svm_     β”‚  β”‚
             β”‚      β”‚  β”‚  best_ml.xml)   β”‚  β”‚
             β”‚      β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
             β”‚      β”‚  Output: Biodata Diri β”‚
             β”‚      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
             β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚  Cloud Firestoreβ”‚
    β”‚  (User Data)    β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ’» Teknologi Stack Keseluruhan

Frontend & Mobile

Technology Version Purpose
Flutter 3.8.1+ Cross-platform framework
Dart 3.8.1+ Programming language
Riverpod 2.3.6 State management
Material Design 3 Latest UI components

Backend & Services

Technology Version Purpose
Firebase Auth 6.1.2 Authentication
Cloud Firestore 6.1.0 NoSQL database
Firebase Realtime DB 12.1.0 Real-time sync
Firebase Storage Latest File storage
Firebase Hosting Latest Web hosting
FCM 16.0.4 Push notifications

Machine Learning

Technology Version Purpose
TensorFlow 2.14+ ML framework
H-5 Built-in High-level API
TFLite 2.14.0 Mobile inference
Flask 3.1.2 API framework

Computer Vision

Technology Version Purpose
OpenCV 4.8+ Image processing
scikit-learn 1.3+ ML (SVM)
NumPy 1.24+ Numerical ops
Pillow 10.0+ Image handling

Development Tools

Tool Purpose
Git & GitHub Version control
VS Code IDE
Github Copilot Improve Code
Firebase CLI Deployment
Postman API testing

πŸš€ Instalasi dan Setup

Prerequisites Global

Sebelum memulai, pastikan sistem Anda sudah terinstall:

βœ… Git - Version control

git --version
# git version 2.40.0 or higher

βœ… Python - 3.8 hingga 3.11

python --version
# Python 3.10.x recommended

βœ… Flutter SDK - 3.8.1 or higher

flutter --version
# Flutter 3.8.1 β€’ channel stable

βœ… Node.js & npm - Untuk Firebase CLI (optional)

node --version
npm --version

πŸ”§ Setup Per Komponen

1️⃣ Clone Repository

git clone https://github.com/Ruphasa/Four-Heavenly-Principle.git
cd Four-Heavenly-Principle

2️⃣ Setup Machine Learning API

cd "Machine Learning/ktpfraud_api"

# Buat virtual environment
python -m venv venv

# Aktivasi virtual environment
# Windows PowerShell:
.\venv\Scripts\Activate.ps1
# Windows CMD:
venv\Scripts\activate.bat
# Linux/Mac:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Verifikasi model tersedia
ls saved_models/ktp_fraud_cnn_tampering_v1.tflite

# Run development server
python app.py
# Server akan berjalan di http://localhost:5000

Test API:

# Health check
curl http://localhost:5000/health

# Predict (with image file)
curl -X POST http://localhost:5000/predict \
  -F "file=@path/to/ktp_image.jpg"

Production Deployment:

# Dengan Gunicorn
gunicorn --bind 0.0.0.0:5000 --workers 4 app:app

3️⃣ Setup PCVK (Computer Vision)

cd ../../PCVK

# Install dependencies
pip install opencv-python opencv-contrib-python
pip install scikit-learn numpy matplotlib pillow

# Atau gunakan requirements.txt
pip install -r requirements.txt

# Verifikasi instalasi
python -c "import cv2; print('OpenCV:', cv2.__version__)"
python -c "import sklearn; print('scikit-learn:', sklearn.__version__)"

# Model sudah tersedia di:
# - digit_svm_best_ml.xml (pre-trained SVM model)
# - digit_feature_config.json (configuration)

Test PCVK:

# test_pcvk.py
import cv2
import json

# Load model
svm = cv2.ml.SVM_load('digit_svm_best_ml.xml')

# Load config
with open('digit_feature_config.json', 'r') as f:
    config = json.load(f)

print("PCVK loaded successfully!")
print("Config:", config)

4️⃣ Setup Pentagram (Flutter App)

cd ../pentagram

# Install Flutter dependencies
flutter pub get

# Verify Flutter installation
flutter doctor

# Run app pada device/emulator
flutter run

# Atau specify device
flutter devices
flutter run -d <device_id>

Firebase Configuration:

  1. Buat Firebase Project

  2. Add Android App

    • Package name: com.example.pentagram
    • Download google-services.json
    • Place in android/app/
  3. Add iOS App (if needed)

    • Bundle ID: com.example.pentagram
    • Download GoogleService-Info.plist
    • Place in ios/Runner/
  4. Enable Firebase Services

    • Authentication (Email/Password)
    • Cloud Firestore
    • Realtime Database
    • Cloud Messaging
    • Storage
    • Hosting (untuk web)
  5. Generate Firebase Config

    # Install FlutterFire CLI
    dart pub global activate flutterfire_cli
    
    # Configure Firebase
    flutterfire configure
  6. Update ML API URL Edit lib/services/ktp_verification_service.dart:

    final apiUrl = 'http://localhost:5000/predict'; // Development
    // atau
    final apiUrl = 'https://your-ml-api.com/predict'; // Production

Build untuk Production:

# Android APK
flutter build apk --release

# Android App Bundle (untuk Play Store)
flutter build appbundle --release

# iOS (Mac only)
flutter build ios --release

# Web
flutter build web --release

# Deploy web ke Firebase
firebase deploy --only hosting

πŸ”— Integration Testing

Test integrasi lengkap:

  1. Start ML API

    cd "Machine Learning/ktpfraud_api"
    python app.py
  2. Run Flutter App

    cd pentagram
    flutter run
  3. Test KTP Verification Flow

    • Open Pentagram app
    • Navigate to Profile β†’ Verifikasi KTP
    • Upload foto KTP
    • Observe:
      • βœ… Image sent to ML API
      • βœ… API processes dengan PCVK
      • βœ… Result returned (VALID/FRAUD)
      • βœ… UI updates accordingly
      • βœ… Data saved to Firebase

πŸ› Troubleshooting

Issue: ML API Connection Error

Error: Failed to connect to http://localhost:5000

Solution:

  • Pastikan ML API running
  • Check firewall settings
  • Untuk Android emulator, use http://10.0.2.2:5000
  • Untuk iOS simulator, use http://localhost:5000

Issue: Firebase Not Initialized

Error: Firebase has not been initialized

Solution:

flutterfire configure
flutter pub get
flutter run

Issue: OpenCV Installation Error

ERROR: Could not build wheels for opencv-python

Solution (Windows):

pip install --upgrade pip
pip install opencv-python-headless

Issue: Flutter Doctor Issues

flutter doctor
# Fix any red X marks

Common fixes:

  • Android: Install Android Studio + SDK
  • iOS: Install Xcode (Mac only)
  • cmdline-tools: flutter doctor --android-licenses

πŸ“š Dokumentasi Lengkap

Berikut dokumentasi detail untuk setiap sub-project dalam ekosistem Four Heavenly Principle.


πŸ€– Machine Learning - KTP Fraud Detection

πŸ“Š Overview

Sistem deteksi fraud KTP menggunakan Convolutional Neural Network (CNN) untuk mengidentifikasi tanda-tanda tampering atau manipulasi digital pada gambar KTP Indonesia.

🎯 Key Features

  • Binary Classification: Membedakan KTP VALID vs FRAUD dengan Deep Learning
  • CNN Architecture: 4 convolutional layers untuk feature extraction
  • OCR Integration: Ekstraksi otomatis NIK setelah validasi
  • Data Augmentation: Rotasi, flip, brightness, zoom untuk robustness
  • TFLite Deployment: Model optimized untuk mobile & production
  • REST API: Flask-based API dengan CORS support
  • High Performance: 90.5% accuracy fraud detection, <300ms inference time
  • End-to-End Pipeline: Upload KTP β†’ Fraud Check (CNN) β†’ OCR Extract (SVM)

πŸ—οΈ Model Architecture

Input: 224x224x3 RGB Image
    ↓
Rescaling Layer (Normalization /255)
    ↓
Conv2D Block 1: 32 filters (3x3) β†’ ReLU β†’ MaxPool2D
    ↓
Conv2D Block 2: 64 filters (3x3) β†’ ReLU β†’ MaxPool2D
    ↓
Conv2D Block 3: 128 filters (3x3) β†’ ReLU β†’ MaxPool2D
    ↓
Conv2D Block 4: 256 filters (3x3) β†’ ReLU β†’ MaxPool2D
    ↓
Flatten Layer
    ↓
Dense: 128 units β†’ ReLU β†’ Dropout(0.5)
    ↓
Output: 1 unit β†’ Sigmoid
    ↓
Probability: P(VALID) | P(FRAUD) = 1 - P(VALID)

Model Specifications:

  • Total Parameters: ~2.5M
  • Model Size (TFLite): ~10MB
  • Input Size: 224x224x3
  • Output: Single probability value (0-1)

πŸ“ˆ Performance Metrics

Metric Train Validation Test
Accuracy 94.2% 91.8% 90.5%
Precision 93.5% 90.2% 89.3%
Recall 95.1% 92.5% 91.7%
F1-Score 94.3% 91.3% 90.5%

Confusion Matrix (Test Set):

              Predicted
              VALID  FRAUD
Actual VALID    23      2
       FRAUD     1     74
  • True Positives: 74 (Fraud correctly identified)
  • True Negatives: 23 (Valid correctly identified)
  • False Positives: 2 (Valid wrongly as Fraud)
  • False Negatives: 1 (Fraud wrongly as Valid)

πŸ”§ Training Configuration

IMG_HEIGHT = 224
IMG_WIDTH = 224
BATCH_SIZE = 32
EPOCHS = 20-50

OPTIMIZER = Adam(learning_rate=0.0001)
LOSS = BinaryCrossentropy()
METRICS = ['accuracy', 'precision', 'recall']

Data Augmentation:

data_augmentation = Sequential([
    layers.RandomRotation(0.3),      # Β±30 derajat
    layers.RandomFlip("horizontal"),
    layers.RandomFlip("vertical"),
    layers.RandomBrightness(0.2),
    layers.RandomZoom(0.2),
    layers.RandomTranslation(0.2, 0.2),
])

🌐 API Endpoints

Health Check

GET /health

Response:

{
  "status": "ok"
}

Predict KTP Fraud

POST /predict
Content-Type: multipart/form-data

Request Body:

  • file: Image file (jpg/png)

Response (Valid):

{
  "label": "VALID",
  "p_valid": 0.9234,
  "p_fraud": 0.0766,
  "threshold": 0.5
}

Response (Fraud):

{
  "label": "FRAUD",
  "p_valid": 0.2341,
  "p_fraud": 0.7659,
  "threshold": 0.5
}

πŸ“ File Structure

Machine Learning/
β”œβ”€β”€ coba.ipynb              # Training notebook (main)
β”œβ”€β”€ tes.ipynb              # Experimentation notebook
β”œβ”€β”€ Fraud_Detectio/
β”‚   β”œβ”€β”€ train/             # Training data
β”‚   β”‚   └── 0/             # Valid KTP samples
β”‚   β”œβ”€β”€ val/               # Validation data
β”‚   β”‚   β”œβ”€β”€ 0/             # Valid
β”‚   β”‚   β”œβ”€β”€ 90/            # Fraud (rotated)
β”‚   β”‚   β”œβ”€β”€ 180/           # Fraud (rotated)
β”‚   β”‚   └── 270/           # Fraud (rotated)
β”‚   β”œβ”€β”€ test/              # Test data (same structure as val)
β”‚   └── saved_models/
β”‚       β”œβ”€β”€ ktp_fraud_cnn_tampering_v1.h5      # Full Keras model
β”‚       └── ktp_fraud_cnn_tampering_v1.tflite  # TFLite model
β”œβ”€β”€ ktpfraud_api/
β”‚   β”œβ”€β”€ app.py             # Flask application
β”‚   β”œβ”€β”€ requirements.txt   # Python dependencies
β”‚   β”œβ”€β”€ runtime.txt        # Python version
β”‚   └── saved_models/
β”‚       └── ktp_fraud_cnn_tampering_v1.tflite
└── README.md

πŸš€ Quick Start ML

# Navigate to API directory
cd "Machine Learning/ktpfraud_api"

# Create virtual environment
python -m venv venv
.\venv\Scripts\Activate.ps1  # Windows PowerShell

# Install dependencies
pip install -r requirements.txt

# Run API
python app.py
# Server runs at http://localhost:5000

Test with cURL:

curl -X POST http://localhost:5000/predict \
  -F "file=@sample_ktp.jpg"

πŸ’‘ Key Learning Points - ML

  1. Data Augmentation is Critical: Meningkatkan accuracy dari 85% β†’ 91%
  2. TFLite Conversion: Reduce model size 4x dengan minimal accuracy loss
  3. API Design: Proper error handling dan CORS configuration essential
  4. Deployment: Use tflite-runtime (5MB) instead of full tensorflow (500MB)

πŸ“· PCVK - Pengolahan Citra & Visi Komputer

πŸ“Š Overview

PCVK (Pengolahan Citra & Visi Komputer) adalah library untuk OCR (Optical Character Recognition), image processing, dan digit recognition pada KTP menggunakan OpenCV dan Machine Learning (SVM - Support Vector Machine).

Metode yang Digunakan:

  • Image Processing: OpenCV untuk preprocessing (grayscale, denoising, binarization)
  • Feature Extraction: HOG (Histogram of Oriented Gradients) untuk capture shape patterns
  • Classification: SVM dengan RBF kernel untuk digit recognition (0-9)
  • OCR Pipeline: Segmentasi digit β†’ Feature extraction β†’ SVM classification β†’ Reconstruction

🎯 Key Features

  • OCR Pipeline Lengkap: Full optical character recognition untuk KTP
  • Image Preprocessing: Grayscale, noise reduction, binarization dengan OpenCV
  • HOG Feature Extraction: Histogram of Oriented Gradients (1764 dimensions)
  • SVM Classification: Support Vector Machine dengan RBF kernel untuk digit recognition
  • ROI Detection: Automatic region of interest detection untuk NIK fields
  • 93.5% Accuracy: High performance pada digit recognition
  • Fast Inference: <20ms per digit, ~300ms untuk full NIK extraction
  • Configuration-Driven: JSON-based config untuk flexibility
  • Traditional ML Approach: SVM terbukti efektif untuk OCR tasks dengan minimal resource

πŸ—οΈ Processing Pipeline

Raw KTP Image
    ↓
1. Grayscale Conversion
    ↓
2. Noise Reduction (Gaussian Blur)
    ↓
3. Binarization (Otsu's Thresholding)
    ↓
4. Morphological Operations (Opening/Closing)
    ↓
5. Digit Region Extraction (ROI)
    ↓
6. Individual Digit Segmentation
    ↓
7. HOG Feature Extraction
    ↓
8. SVM Classification (0-9)
    ↓
9. Post-processing & Validation
    ↓
Extracted NIK with Confidence Scores

πŸ”¬ HOG Feature Extraction

Histogram of Oriented Gradients (HOG):

  1. Gradient Computation: Calculate magnitude & direction
  2. Cell Histograms: Divide image into 8x8 pixel cells
  3. Block Normalization: Normalize across 2x2 cell blocks
  4. Feature Vector: Concatenate all histograms

Configuration:

{
  "image_size": [64, 64],
  "cell_size": [8, 8],
  "block_size": [16, 16],
  "block_stride": [8, 8],
  "orientations": 9
}

Feature Dimensions:

  • Image: 64x64 pixels
  • Cells: 8x8 = 64 cells per image
  • Blocks: 7x7 = 49 blocks (with 50% overlap)
  • Features per block: 2x2 cells Γ— 9 orientations = 36
  • Total features: 49 Γ— 36 = 1764 dimensions

πŸ€– SVM Classifier

Model Specifications:

  • Algorithm: Support Vector Machine
  • Kernel: RBF (Radial Basis Function)
  • Classes: 10 (digits 0-9)
  • Training Samples: 1200+ digit images
  • Hyperparameters:
    • C (regularization): 10.0
    • Gamma: 'scale' (automatic)

Why SVM?

  • Effective in high dimensions (1764 features)
  • Memory efficient (only support vectors)
  • Fast inference (~2ms per digit)
  • Good generalization with limited data

πŸ“ˆ Performance Metrics

confusionMatrik

πŸ“ File Structure

PCVK/
β”œβ”€β”€ digit_svm_best_ml.xml      # Pre-trained SVM model
β”œβ”€β”€ digit_feature_config.json  # HOG configuration
β”œβ”€β”€ Dataset/                    # Training dataset
β”‚   β”œβ”€β”€ 0/                     # Digit 0 samples
β”‚   β”œβ”€β”€ 1/                     # Digit 1 samples
β”‚   β”œβ”€β”€ ...
β”‚   └── Z/                     # Alphabet z samples
└── README.md

πŸš€ Quick Start PCVK

import cv2
import numpy as np
import json

# Load model and config
svm = cv2.ml.SVM_load('digit_svm_best_ml.xml')
with open('digit_feature_config.json', 'r') as f:
    config = json.load(f)

# Preprocess digit image
def preprocess_digit(img):
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    resized = cv2.resize(gray, tuple(config['image_size']))
    _, binary = cv2.threshold(resized, 0, 255, 
                              cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
    return binary

# Extract HOG features
def extract_hog(img):
    hog = cv2.HOGDescriptor(
        _winSize=tuple(config['image_size']),
        _blockSize=tuple(config['block_size']),
        _blockStride=tuple(config['block_stride']),
        _cellSize=tuple(config['cell_size']),
        _nbins=config['orientations']
    )
    features = hog.compute(img)
    return features.flatten().reshape(1, -1).astype(np.float32)

# Recognize digit
def recognize_digit(img_path):
    img = cv2.imread(img_path)
    processed = preprocess_digit(img)
    features = extract_hog(processed)
    
    digit = svm.predict(features)[0][0]
    return int(digit)

# Usage
result = recognize_digit('digit_sample.jpg')
print(f"Recognized digit: {result}")

πŸ’‘ Key Learning Points - PCVK

  1. HOG Features Powerful: Capture shape/structure, robust to variations
  2. Preprocessing Critical: 70% of accuracy depends on good preprocessing
  3. Traditional ML Still Relevant: SVM+HOG competitive with basic CNNs
  4. Configuration Management: JSON config enables easy experimentation

πŸ“± Pentagram - Aplikasi Mobile Flutter

πŸ“Š Overview

Pentagram (Jawara Pintar) adalah aplikasi mobile cross-platform untuk manajemen administrasi Rukun Warga (RW) yang dibangun dengan Flutter dan Firebase.

🎯 Fitur Lengkap

1. Dashboard & Analytics πŸ“Š

  • Real-time statistics (jumlah warga, keluarga, RT)
  • Grafik interaktif (fl_chart)
  • Quick actions ke fitur penting
  • Recent activities timeline

2. Manajemen Warga πŸ‘₯

  • CRUD data penduduk lengkap
  • Struktur keluarga & relasi
  • Mutasi keluarga (pindah, meninggal, dll)
  • Data rumah & penghuni
  • Verifikasi KTP dengan AI: Fraud detection menggunakan CNN
  • OCR KTP Otomatis: Auto-fill data dari scan KTP (NIK, nama)
  • Integrasi ML API untuk AI-powered verification

3. Keuangan RW πŸ’°

  • Pemasukan: Iuran bulanan, sukarela, lainnya
  • Pengeluaran: Track semua pengeluaran RW
  • Laporan keuangan periode tertentu
  • Grafik pemasukan vs pengeluaran
  • Export ke Excel/PDF

4. Broadcast & Kegiatan πŸ“’

  • Broadcast pengumuman ke semua warga
  • Manajemen event RW
  • Push notification via FCM
  • RSVP system untuk event

5. Komunikasi πŸ’¬

  • Sistem pesan warga ↔ pengurus
  • Penerimaan warga baru
  • Channel transfer tanggung jawab
  • Log aktivitas (audit trail)

6. Autentikasi & Security πŸ”

  • Firebase Authentication
  • Multi-role: Admin, Ketua RW, Bendahara, Sekretaris, RT
  • Permission-based access
  • Session management

πŸ—οΈ Architecture - Pentagram

State Management: Riverpod

UI Layer (Pages & Widgets)
        ↓
Providers (Riverpod)
        ↓
Repositories (Data Access)
        ↓
Firebase Services

Example: User Data Flow

// 1. Provider Definition
final userListProvider = StreamProvider<List<User>>((ref) {
  final repo = ref.watch(userRepositoryProvider);
  return repo.getUsersStream();
});

// 2. Repository Implementation
class UserRepository {
  final FirebaseFirestore _firestore;
  
  Stream<List<User>> getUsersStream() {
    return _firestore.collection('users')
      .snapshots()
      .map((snapshot) => snapshot.docs
        .map((doc) => User.fromFirestore(doc))
        .toList()
      );
  }
}

// 3. Widget Consumption
class UserListPage extends ConsumerWidget {
  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final usersAsync = ref.watch(userListProvider);
    
    return usersAsync.when(
      data: (users) => ListView.builder(...),
      loading: () => CircularProgressIndicator(),
      error: (err, stack) => ErrorWidget(err),
    );
  }
}

πŸ” Firebase Configuration

Services Used:

  1. Firebase Authentication - Email/password login
  2. Cloud Firestore - Main database (users, families, etc.)
  3. Realtime Database - Real-time messaging
  4. Cloud Storage - File uploads (KTP images)
  5. Cloud Messaging (FCM) - Push notifications
  6. Firebase Hosting - Web deployment

Security Rules Example (Firestore):

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // Users can read their own data
    match /users/{userId} {
      allow read: if request.auth != null;
      allow write: if request.auth.uid == userId || 
                      isAdmin();
    }
    
    // Helper function
    function isAdmin() {
      return get(/databases/$(database)/documents/users/$(request.auth.uid))
             .data.role == 'admin';
    }
    
    // Default: authenticated users can read
    match /{document=**} {
      allow read: if request.auth != null;
      allow write: if false;  // Customize per collection
    }
  }
}

πŸš€ Build & Deployment

Development:

flutter run

Production Builds:

# Android APK
flutter build apk --release

# Android App Bundle (Play Store)
flutter build appbundle --release

# iOS (Mac)
flutter build ios --release

# Web
flutter build web --release
firebase deploy --only hosting

πŸ’‘ Key Learning Points - Pentagram

  1. Riverpod State Management: Clean, testable, reactive state
  2. Firebase Integration: Complete backend without custom server
  3. ML API Integration: Seamless connection dengan external services
  4. Cross-Platform: Single codebase untuk Android, iOS, Web
  5. Material Design 3: Modern, beautiful UI out of the box

πŸ‘₯ Kontributor

Pentagram Development Team

Developer GitHub Contributions
Rizqi Fauzan @Ruphasa Back-End Engineer
Muhammad RafiΒ Rajendra @rafiirajendra Machine Learning Engineer + integrasi mobile
Nathanael Juan Gracedo @NathanaelGracedo Front-End Enginerr
Faishal HaristΒ Rahmawan @ishall26 Pengolahan Citra & Visi Komputer Engineer + integrasi mobile

ML & PCVK

  • Machine Learning Engineer: Development CNN model & Res-Flask API
  • Computer Vision Engineer: Development SVM Model & Res-Flask API

πŸ“ LAPORAN REFLEKTIF MENDALAM

Dokumen Laporan Reflektif Mendalam

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages