Repository navigation
Expand file tree
/
Copy pathJavaCamResView.kt
More file actions
46 lines (35 loc) · 1.65 KB
/
Copy pathJavaCamResView.kt
File metadata and controls
46 lines (35 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.openvins.android
import android.content.Context
import android.hardware.Camera
import android.util.AttributeSet
import android.util.Log
import org.opencv.android.JavaCameraView
class JavaCamResView(context: Context?, attrs: AttributeSet?) : JavaCameraView(context, attrs) {
override fun initializeCamera(width: Int, height: Int): Boolean {
// Set the max frame size
super.setMaxFrameSize(640, 480)
// Initialize our camera
if (!super.initializeCamera(width, height)) {
return false
}
// Set the focus mode to either infinity or fixed
val params: Camera.Parameters = mCamera.getParameters()
// Try to set focus to infinity first, then fixed as fallback
if (params.supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_INFINITY)) {
params.focusMode = Camera.Parameters.FOCUS_MODE_INFINITY
Log.d("JavaCamResView", "Focus mode set to INFINITY")
} else if (params.supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_FIXED)) {
params.focusMode = Camera.Parameters.FOCUS_MODE_FIXED
Log.d("JavaCamResView", "Focus mode set to FIXED")
} else {
Log.w("JavaCamResView", "Neither INFINITY nor FIXED focus modes are supported. Available modes: ${params.supportedFocusModes}")
// Keep auto if neither is available (though this shouldn't happen on most cameras)
}
// Limit the exposure
params.setAutoExposureLock(false)
params.exposureCompensation = -10
// Finally write our parameters
mCamera.setParameters(params)
return true
}
}