Android, like many systems, enables the programmer to specify GUI layouts in XML files. Our Java code can load an entire view or pieces of it from these XML files.
Goldgesture has a simple layout that contains only a camera preview on which we will draw some additional graphics using OpenCV. The camera preview is represented by an OpenCV class called JavaCameraView
. Let's edit res/layout/activity_camera.xml
to fill the layout with JavaCameraView
, using the front-facing camera, as follows:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:opencv="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" > <org.opencv.android.JavaCameraView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/camera_view" opencv:camera_id="front" /> </LinearLayout>
Alternatively, OpenCV also provides a class called NativeCameraView
. Both JavaCameraView
and NativeCameraView
are implementations of an interface called CameraBridgeViewBase
. The difference is that NativeCameraView
accesses the camera via a lower-level API, which yields a higher frame rate but is often broken/not working on new devices and/or new versions of Android.