refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게 [공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류. 문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인). - Topic_Programming → Domain_Programming (내부 구조 보존) - Topic_Graphic → Domain_Design - Topic_Business → Domain_Product - Topic_General → Domain_General - _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning), Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing) - 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서) - 빈 폴더 정리 (memory/procedures) - 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
---
|
||||
id: android-camerax-patterns
|
||||
title: Android CameraX — 카메라 / 이미지 분석
|
||||
category: Coding
|
||||
status: draft
|
||||
source_trust_level: B
|
||||
verification_status: conceptual
|
||||
created_at: 2026-05-09
|
||||
updated_at: 2026-05-09
|
||||
tags: [android, camera, camerax, vibe-coding]
|
||||
tech_stack: { language: "Kotlin / CameraX 1.4+", applicable_to: ["Android"] }
|
||||
applied_in: []
|
||||
aliases: [Camera2, ImageCapture, ImageAnalysis, Preview, lifecycle camera]
|
||||
---
|
||||
|
||||
# Android CameraX
|
||||
|
||||
> Camera2 의 lifecycle-aware wrapper. **Preview / ImageCapture / ImageAnalysis / VideoCapture** 4종 use case. 디바이스 호환성 자동 처리.
|
||||
|
||||
## 📖 핵심 개념
|
||||
- ProcessCameraProvider: 부팅.
|
||||
- UseCase: Preview / ImageCapture / ImageAnalysis / VideoCapture.
|
||||
- bindToLifecycle: lifecycle 에 묶어 자동 시작/정지.
|
||||
|
||||
## 💻 코드 패턴
|
||||
|
||||
### 의존성
|
||||
```kotlin
|
||||
implementation("androidx.camera:camera-core:1.4.0")
|
||||
implementation("androidx.camera:camera-camera2:1.4.0")
|
||||
implementation("androidx.camera:camera-lifecycle:1.4.0")
|
||||
implementation("androidx.camera:camera-view:1.4.0")
|
||||
```
|
||||
|
||||
### Preview + Capture (Compose)
|
||||
```kotlin
|
||||
@Composable
|
||||
fun CameraScreen() {
|
||||
val ctx = LocalContext.current
|
||||
val lifecycleOwner = LocalLifecycleOwner.current
|
||||
val previewView = remember { PreviewView(ctx) }
|
||||
var imageCapture by remember { mutableStateOf<ImageCapture?>(null) }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
val provider = ProcessCameraProvider.getInstance(ctx).get()
|
||||
|
||||
val preview = Preview.Builder().build().also {
|
||||
it.setSurfaceProvider(previewView.surfaceProvider)
|
||||
}
|
||||
val capture = ImageCapture.Builder()
|
||||
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
|
||||
.build()
|
||||
imageCapture = capture
|
||||
|
||||
try {
|
||||
provider.unbindAll()
|
||||
provider.bindToLifecycle(
|
||||
lifecycleOwner,
|
||||
CameraSelector.DEFAULT_BACK_CAMERA,
|
||||
preview, capture
|
||||
)
|
||||
} catch (e: Exception) { log.error("camera bind failed", e) }
|
||||
}
|
||||
|
||||
Box {
|
||||
AndroidView(factory = { previewView })
|
||||
Button(onClick = { imageCapture?.takePictureToDisk(ctx) }) { Text("촬영") }
|
||||
}
|
||||
}
|
||||
|
||||
fun ImageCapture.takePictureToDisk(ctx: Context) {
|
||||
val file = File(ctx.cacheDir, "shot_${System.currentTimeMillis()}.jpg")
|
||||
val output = ImageCapture.OutputFileOptions.Builder(file).build()
|
||||
takePicture(output, ContextCompat.getMainExecutor(ctx),
|
||||
object : ImageCapture.OnImageSavedCallback {
|
||||
override fun onImageSaved(o: ImageCapture.OutputFileResults) { /* file ready */ }
|
||||
override fun onError(e: ImageCaptureException) { log.error("capture failed", e) }
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
### ImageAnalysis — ML / barcode
|
||||
```kotlin
|
||||
val analyzer = ImageAnalysis.Builder()
|
||||
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
|
||||
.build()
|
||||
.also {
|
||||
it.setAnalyzer(Executors.newSingleThreadExecutor()) { imageProxy ->
|
||||
val mediaImage = imageProxy.image ?: return@setAnalyzer
|
||||
val image = InputImage.fromMediaImage(mediaImage, imageProxy.imageInfo.rotationDegrees)
|
||||
barcodeScanner.process(image)
|
||||
.addOnSuccessListener { codes -> codes.forEach { onScan(it.rawValue) } }
|
||||
.addOnCompleteListener { imageProxy.close() } // 반드시 close
|
||||
}
|
||||
}
|
||||
|
||||
provider.bindToLifecycle(lifecycleOwner, CameraSelector.DEFAULT_BACK_CAMERA, preview, analyzer)
|
||||
```
|
||||
|
||||
### Permission
|
||||
```kotlin
|
||||
val permission = rememberPermissionState(Manifest.permission.CAMERA)
|
||||
LaunchedEffect(Unit) { permission.launchPermissionRequest() }
|
||||
if (!permission.status.isGranted) return // PermissionRationale UI
|
||||
```
|
||||
|
||||
### Video capture
|
||||
```kotlin
|
||||
val recorder = Recorder.Builder()
|
||||
.setQualitySelector(QualitySelector.from(Quality.HD))
|
||||
.build()
|
||||
val videoCapture = VideoCapture.withOutput(recorder)
|
||||
provider.bindToLifecycle(lifecycleOwner, selector, preview, videoCapture)
|
||||
|
||||
val output = MediaStoreOutputOptions.Builder(...).build()
|
||||
recording = videoCapture.output.prepareRecording(ctx, output)
|
||||
.start(ContextCompat.getMainExecutor(ctx)) { event -> ... }
|
||||
// 종료
|
||||
recording?.stop()
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준
|
||||
| 사용 | UseCase 조합 |
|
||||
|---|---|
|
||||
| 단순 사진 | Preview + ImageCapture |
|
||||
| QR / barcode 스캔 | Preview + ImageAnalysis |
|
||||
| ML 분석 (얼굴, OCR) | Preview + ImageAnalysis |
|
||||
| 비디오 녹화 | Preview + VideoCapture |
|
||||
| 사진 + 비디오 동시 | Preview + ImageCapture + VideoCapture (제한 있음) |
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **imageProxy.close() 누락**: backpressure → analyzer 멈춤.
|
||||
- **lifecycle 안 묶음**: 백그라운드에서 카메라 점유 → 배터리.
|
||||
- **메인 스레드에서 ML 처리**: UI 멈춤. 별도 executor.
|
||||
- **여러 use case 가 디바이스 한계 초과**: bind 실패. 한 번에 적게.
|
||||
- **Preview rotation 안 처리**: 회전 시 이상.
|
||||
- **권한 거부 후 silent**: 가이드 UI.
|
||||
|
||||
## 🤖 LLM 활용 힌트
|
||||
- CameraX + lifecycle bind + 단일 executor analyzer 패턴 표준.
|
||||
- ML Kit 결합 자주.
|
||||
|
||||
## 🔗 관련 문서
|
||||
- [[Android_Lifecycle_Aware_Components]]
|
||||
- [[iOS_Background_Tasks]]
|
||||
Reference in New Issue
Block a user