spacebox/demo/camera/README.md

2.9 KiB

Camera capture demo using OpenCV

Display camera input using the OpenCV library.

Requirements

SPACEBOX

The required libraries for the overall framework must be installed first. Follow the instructions in Installing Requirements in the main README.

OpenCV

Follow the instructions in the main README to build OpenCV for Linux, Android, or both, depending on which platforms the demo is going to be built for.

Build

config

In config.json, render driver should be set to opengl on Linux and opengles2 on Android (in other projects, opengles2 can work on Linux, which is why this is a config value rather than built into the engine).

Linux

In addition to the usual SPACEBOX paths to edit, there are two paths to configure in the Makefile under the Linux build section. Edit OPENCV_INCPATH and OPENCV_LINUX_LDPATH to match locations in the OpenCV project compiled earlier. Then the camera target should compile.

make camera

After it compiles, run the binary to see the camera input.

./camera

Android

Compiling with NDK 24 may cause an error cannot open crtbegin_so.o. This thread's suggestion of using the -nostartfiles linker flag seems to fix it. It may need to be inserted into the main SDL Android.mk file, which is in the root of the SDL source package installed earlier and referenced in this project's Makefile. Line 83 should be changed to:

LOCAL_LDFLAGS := -Wl,--no-undefined -nostartfiles

In the Makefile, edit OPENCV_ANDROID_SDK to match the location of the folder built earlier. At this point, the target should be able to build.

make build/android/ooo.shampoo.camera

An APK will be output to build/android/ooo.shampoo.camera/app-debug.apk which can be loaded onto a device or emulator. After loading the APK, make sure to give camera permissions to the app. Then, run the app.

Settings -> Apps & notifications -> All apps -> Camera Capture Test -> Permissions -> Camera

The explanation in the main README for the fill_screen Android build applies to this project, with a few additional notes.

  • The NDK version is raised to 24, and the minimum SDK version is 21 (this was chosen arbitrarily, but it was failing with version 18).
  • There are additional steps added in the Makefile for linking to the pre-built shared libraries for OpenCV and libtbb (which was generated by the OpenCV build process). See this thread for more info on how to link pre-built libraries per-ABI to an Android build using GNU make.
  • There is an extra target for including the config JSON and shaders as assets in the Android project.