Hello community,
I’m developing a surveillance application using OpenCV on Android, and I’m encountering an issue where the screen stays black when trying to display the camera preview on both a physical device (Konka N15) and an emulator. OpenCV seems to load correctly, but no image is shown on the screen.
Here’s a snippet of the code that sets up and handles the camera view:
class MainActivity : ComponentActivity(), CvCameraViewListener2 {
private var cameraView: CameraBridgeViewBase? = null;
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState);
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
if (!OpenCVLoader.initDebug()) {
Log.e("OpenCV", "Unable to load OpenCV!");
} else {
Log.d("OpenCV", "OpenCV loaded successfully!");
}
setContent {
MaterialTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
AndroidView(
factory = { context ->
JavaCamera2View(context, -1).apply {
setCvCameraViewListener(this@MainActivity);
layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
visibility = android.view.View.VISIBLE;
cameraView = this;
}
},
modifier = Modifier.fillMaxSize()
);
}
};
}
checkCameraPermission();
}
override fun onCameraFrame(inputFrame: CvCameraViewFrame): Mat {
Log.d("CameraFrame", "Received a frame");
return inputFrame.rgba();
}
// Additional methods...
}
During execution, several logs are recorded that I am not sure if they are related to the problem:
2024-04-22 18:49:14.636 mara_vigilanci com.example.camara_vigilancia W ClassLoaderContext classpath size mismatch. expected=0, found=1
2024-04-22 18:49:14.719 linker com.example.camara_vigilancia W Warning: "/data/app/~~Zvykmk4-FMii-EuRyKO8nA==/com.example.camara_vigilancia-aLuC20vWP-EbTNTvVuXPYg==/base.apk!/lib/arm64-v8a/libc++_shared.so" unused DT entry: unknown processor-specific (type 0x70000001 arg 0x0)
Could these log messages be indicating an incorrect configuration or some issue that might be affecting the camera rendering in the app? Are there specific settings in the OpenCV or Android environment that I should check to resolve this black screen issue?
Any guidance or suggestions will be greatly appreciated.