Project Based Learning - Politeknik Negeri Malang
Modernisasi Administrasi Rukun Warga melalui Teknologi Digital
π About β’ π Installation β’ π Full Docs β’ π Reflection
- Machine Learning - KTP Fraud Detection
- PCVK - Python Computer Vision KTP
- Pentagram - Flutter Mobile App
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:
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/TensorFlowktp_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
Library computer vision untuk OCR digit recognition KTP:
- SVM Classifier: Pre-trained model
digit_svm_best_ml.xmluntuk 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.ipynbuntuk 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
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)
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
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β 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) β β
β ββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββ
β 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) β
βββββββββββββββββββ
| 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 |
| 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 |
| 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 |
| Technology | Version | Purpose |
|---|---|---|
| OpenCV | 4.8+ | Image processing |
| scikit-learn | 1.3+ | ML (SVM) |
| NumPy | 1.24+ | Numerical ops |
| Pillow | 10.0+ | Image handling |
| Tool | Purpose |
|---|---|
| Git & GitHub | Version control |
| VS Code | IDE |
| Github Copilot | Improve Code |
| Firebase CLI | Deployment |
| Postman | API testing |
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 --versiongit clone https://github.com/Ruphasa/Four-Heavenly-Principle.git
cd Four-Heavenly-Principlecd "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:5000Test 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:appcd ../../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)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:
-
Buat Firebase Project
- Buka https://console.firebase.google.com/
- Create new project: "Pentagram" atau "Jawara-Pintar"
- Enable Google Analytics (optional)
-
Add Android App
- Package name:
com.example.pentagram - Download
google-services.json - Place in
android/app/
- Package name:
-
Add iOS App (if needed)
- Bundle ID:
com.example.pentagram - Download
GoogleService-Info.plist - Place in
ios/Runner/
- Bundle ID:
-
Enable Firebase Services
- Authentication (Email/Password)
- Cloud Firestore
- Realtime Database
- Cloud Messaging
- Storage
- Hosting (untuk web)
-
Generate Firebase Config
# Install FlutterFire CLI dart pub global activate flutterfire_cli # Configure Firebase flutterfire configure
-
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 hostingTest integrasi lengkap:
-
Start ML API
cd "Machine Learning/ktpfraud_api" python app.py
-
Run Flutter App
cd pentagram flutter run -
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
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
Error: Firebase has not been initialized
Solution:
flutterfire configure
flutter pub get
flutter runERROR: Could not build wheels for opencv-python
Solution (Windows):
pip install --upgrade pip
pip install opencv-python-headlessflutter doctor
# Fix any red X marksCommon fixes:
- Android: Install Android Studio + SDK
- iOS: Install Xcode (Mac only)
- cmdline-tools:
flutter doctor --android-licenses
Berikut dokumentasi detail untuk setiap sub-project dalam ekosistem Four Heavenly Principle.
Sistem deteksi fraud KTP menggunakan Convolutional Neural Network (CNN) untuk mengidentifikasi tanda-tanda tampering atau manipulasi digital pada gambar KTP Indonesia.
- 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)
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)
| 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)
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),
])GET /healthResponse:
{
"status": "ok"
}POST /predict
Content-Type: multipart/form-dataRequest 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
}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
# 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:5000Test with cURL:
curl -X POST http://localhost:5000/predict \
-F "file=@sample_ktp.jpg"- Data Augmentation is Critical: Meningkatkan accuracy dari 85% β 91%
- TFLite Conversion: Reduce model size 4x dengan minimal accuracy loss
- API Design: Proper error handling dan CORS configuration essential
- Deployment: Use tflite-runtime (5MB) instead of full tensorflow (500MB)
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
- 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
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
Histogram of Oriented Gradients (HOG):
- Gradient Computation: Calculate magnitude & direction
- Cell Histograms: Divide image into 8x8 pixel cells
- Block Normalization: Normalize across 2x2 cell blocks
- 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
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
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
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}")- HOG Features Powerful: Capture shape/structure, robust to variations
- Preprocessing Critical: 70% of accuracy depends on good preprocessing
- Traditional ML Still Relevant: SVM+HOG competitive with basic CNNs
- Configuration Management: JSON config enables easy experimentation
Pentagram (Jawara Pintar) adalah aplikasi mobile cross-platform untuk manajemen administrasi Rukun Warga (RW) yang dibangun dengan Flutter dan Firebase.
- Real-time statistics (jumlah warga, keluarga, RT)
- Grafik interaktif (fl_chart)
- Quick actions ke fitur penting
- Recent activities timeline
- 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
- Pemasukan: Iuran bulanan, sukarela, lainnya
- Pengeluaran: Track semua pengeluaran RW
- Laporan keuangan periode tertentu
- Grafik pemasukan vs pengeluaran
- Export ke Excel/PDF
- Broadcast pengumuman ke semua warga
- Manajemen event RW
- Push notification via FCM
- RSVP system untuk event
- Sistem pesan warga β pengurus
- Penerimaan warga baru
- Channel transfer tanggung jawab
- Log aktivitas (audit trail)
- Firebase Authentication
- Multi-role: Admin, Ketua RW, Bendahara, Sekretaris, RT
- Permission-based access
- Session management
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),
);
}
}Services Used:
- Firebase Authentication - Email/password login
- Cloud Firestore - Main database (users, families, etc.)
- Realtime Database - Real-time messaging
- Cloud Storage - File uploads (KTP images)
- Cloud Messaging (FCM) - Push notifications
- 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
}
}
}Development:
flutter runProduction 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- Riverpod State Management: Clean, testable, reactive state
- Firebase Integration: Complete backend without custom server
- ML API Integration: Seamless connection dengan external services
- Cross-Platform: Single codebase untuk Android, iOS, Web
- Material Design 3: Modern, beautiful UI out of the box
| 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 |
- Machine Learning Engineer: Development CNN model & Res-Flask API
- Computer Vision Engineer: Development SVM Model & Res-Flask API
