Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Getting the camera to work with OpenCV Native Activity Sample

I have managed to compile the Native Activity example in opencv4android. When running it gives a a fatal error.

07-10 22:35:27.694: D/OpenCV::camera(1818): Libraries folder found: /data/app-lib/org.opencv.engine-1/
07-10 22:35:27.694: D/OpenCV::camera(1818): CameraWrapperConnector::connectToLib: folderPath=/data/app-lib/org.opencv.engine-1/
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.3.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.0.3.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.4.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r2.3.3.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.2.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r2.2.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.0.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.1.1.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r3.0.1.so
07-10 22:35:27.694: D/OpenCV::camera(1818): try to load library 'libnative_camera_r4.4.0.so'
07-10 22:35:27.717: D/OpenCV::camera(1818): Loaded library '/data/app-lib/org.opencv.engine-1/libnative_camera_r4.4.0.so'
07-10 22:35:27.717: D/OpenCV_NativeCamera(1818): CameraHandler::initCameraConnect(0x5a839f5d, 0, 0x5ac1df20, 0x0)
07-10 22:35:27.717: D/OpenCV_NativeCamera(1818): Current process name for camera init: org.opencv.samples.NativeActivity
07-10 22:35:27.858: D/OpenCV_NativeCamera(1818): Instantiated new CameraHandler (0x5a839f5d, 0x5ac1df20)
07-10 22:35:27.858: I/OpenCV_NativeCamera(1818): initCameraConnect: [antibanding=auto;antibanding-values=off,auto,50hz,60hz;auto-convergence-mode=frame;auto-convergence-mode-values=;auto-exposure-lock=false;auto-exposure-lock-supported=true;auto-whitebalance-lock=false;auto-whitebalance-lock-supported=true;awb-damping=false;brightness=50;camera-name=S5K4E1GA;contrast=100;current-iso=100;effect=none;effect-values=none,negative,solarize,sepia,mono,natural,vivid,color-swap,blackwhite,whiteboard,blackboard,aqua,posterize;exif-image-description=;exif-make=Google;exif-model=Glass 1;exif-software=Glass-1 XE18.11 1223935;exposure=auto;exposure-compensation=0;exposure-compensation-step=0.1;exposure-mode-values=manual,auto,night,backlighting,spotlight,sports,snow,beach,aperture,small-aperture;flash-mode=off;flash-mode-values=off;focal-length=2.95;focus-mode=infinity;focus-mode-values=infinity;gbce=false;gbce-supported=true;glbce=false;glbce-supported=true;horizontal-view-angle=54.8;ipp=ldc-nsf;ipp-values=off,ldc,nsf,
ldc-nsf;iso=auto;iso-mode-values=auto,100,200,400,
07-10 22:35:27.858: D/OpenCV_NativeCamera(1818): Supported Cameras: (null)
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Picture Sizes: 2592x1944,2560x1888,2528x1856,2592x1728,2592x1458,2560x1888,2400x1350,2304x1296,2240x1344,2160x1440,2112x1728,2112x1188,2048x1152,2048x1536,2016x1512,2016x1134,2000x1600,1920x1080,1600x1200,1600x900,1536x864,1408x792,1344x756,1296x972,1280x1024,1280x720,1152x864,1280x960,1024x768,1024x576,640x480,320x240
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Picture Formats: unused,yuv420sp,yuv420p,yuv422i-yuyv,rgb565,bayer-rggb,jpeg
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Preview Sizes: 1920x1080,1280x960,1280x720,1024x768,1024x576,960x720,800x480,768x576,720x576,720x480,768x576,640x480,640x368,640x360,512x384,512x288,416x304,416x240,352x288,320x240,320x192,256x144,240x160,224x160,176x144,160x120,128x96,960x1280,720x1280,768x1024,576x1024,720x960,480x800,576x768,576x720,576x768,480x720,480x640,368x640,384x512,288x512,304x416,240x416,288x352,240x320,192x320,144x256,160x240,160x224,144x176,120x160,96x128
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Preview Formats: yuv420sp,yuv420p,yuv422i-yuyv,yuv420p
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Preview Frame Rates: 5,10,15,20,24,30,60
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Thumbnail Sizes: 640x480,160x120,200x120,320x240,512x384,352x144,176x144,96x96,0x0
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Whitebalance Modes: auto,daylight,cloudy-daylight,tungsten,fluorescent,incandescent,horizon,sunset,shade,twilight,warm-fluorescent
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Effects: none,negative,solarize,sepia,mono,natural,vivid,color-swap,blackwhite,whiteboard,blackboard,aqua,posterize
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Scene Modes: auto,closeup,landscape,aqua,sports,mood,night-portrait,night-indoor,fireworks,document,barcode,super-night,cine,old-film,action,beach,candlelight,night,party,portrait,snow,steadyphoto,sunset,theatre
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Focus Modes: infinity
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Antibanding Options: off,auto,50hz,60hz
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Flash Modes: off
07-10 22:35:27.881: D/OpenCV_NativeCamera(1818): initCameraConnect: preview format is set to yuv420sp
07-10 22:35:27.889: D/OpenCV_NativeCamera(1818): initCameraConnect: preview format is set to 640x480
07-10 22:35:27.889: A/libc(1818): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 1885 (.NativeActivity)

After that I built the libnative_camera interface from scratch using the opencv source (linux download) (http://code.opencv.org/projects/opencv/wiki/Building_OpenCV4Android_from_trunk). It gives a camera opening error.

07-11 07:06:23.430: I/OCV:libnative_activity(20023): APP_CMD_INIT_WINDOW
07-11 07:06:23.430: D/OpenCV::camera(20023): CvCapture_Android::CvCapture_Android(0)
07-11 07:06:23.437: D/OpenCV::camera(20023): Library name: libopencv_java.so
07-11 07:06:23.437: D/OpenCV::camera(20023): Library base address: 0x591ae000
07-11 07:06:23.539: D/OpenCV::camera(20023): Libraries folder found: /data/app-lib/org.opencv.engine-1/
07-11 07:06:23.539: D/OpenCV::camera(20023): CameraWrapperConnector::connectToLib: folderPath=/data/app-lib/org.opencv.engine-1/
07-11 07:06:23.539: E/OpenCV::camera(20023): ||libnative_camera_r4.3.0.so
07-11 07:06:23.539: E/OpenCV::camera(20023): ||libnative_camera_r4.0.3.so
07-11 07:06:23.539: E/OpenCV::camera(20023): ||libnative_camera_r4.4.0.so
07-11 07:06:23.539: E/OpenCV::camera(20023): ||libnative_camera_r2.3.3.so
07-11 07:06:23.547: E/OpenCV::camera(20023): ||libnative_camera_r4.2.0.so
07-11 07:06:23.547: E/OpenCV::camera(20023): ||libnative_camera_r2.2.0.so
07-11 07:06:23.547: E/OpenCV::camera(20023): ||libnative_camera_r4.0.0.so
07-11 07:06:23.547: E/OpenCV::camera(20023): ||libnative_camera_r4.1.1.so
07-11 07:06:23.547: E/OpenCV::camera(20023): ||libnative_camera_r3.0.1.so
07-11 07:06:23.547: D/OpenCV::camera(20023): try to load library 'libnative_camera_r4.4.0.so'
07-11 07:06:23.570: D/OpenCV::camera(20023): Loaded library '/data/app-lib/org.opencv.engine-1/libnative_camera_r4.4.0.so'
07-11 07:06:23.586: D/OpenCV_NativeCamera(20023): CameraHandler::initCameraConnect(0x598d4f5d, 0, 0x5acc2658, 0x0)
07-11 07:06:23.586: D/OpenCV_NativeCamera(20023): Current process name for camera init: org.opencv.samples.NativeActivity
07-11 07:06:24.094: W/CameraBase(20023): An error occurred while connecting to camera: 0
07-11 07:06:24.094: E/OpenCV_NativeCamera(20023): initCameraConnect: Unable to connect to CameraService
07-11 07:06:24.094: E/OpenCV::camera(20023): CameraWrapperConnector::connectWrapper ERROR: the initializing function returned false
07-11 07:06:24.094: E/OpenCV::camera(20023): Native_camera returned opening error: 6
07-11 07:06:24.094: I/OCV:libnative_activity(20023): Here1
07-11 07:06:24.101: E/OCV:libnative_activity(20023): Cannot get supported camera camera_resolutions
07-11 07:06:24.101: I/OCV:libnative_activity(20023): Here2
07-11 07:06:24.101: I/OCV:libnative_activity(20023): Camera initialized at resolution 640x360

That error lines was traced to opencv-2.4.9/modules/androidcamera/camera_wrapper/camera_wrapper.cpp line 521- 555.

if (Android22ConnectFuncType Android22Connect = (Android22ConnectFuncType)dlsym(CameraHALHandle, Android22ConnectName))
{
    LOGD("Connecting to CameraService v 2.2");
    camera = Android22Connect();
}
else if (Android23ConnectFuncType Android23Connect = (Android23ConnectFuncType)dlsym(CameraHALHandle, Android23ConnectName))
{
    LOGD("Connecting to CameraService v 2.3");
    camera = Android23Connect(localCameraIndex);
}
else if (Android3DConnectFuncType Android3DConnect = (Android3DConnectFuncType)dlsym(CameraHALHandle, Android3DConnectName))
{
    LOGD("Connecting to CameraService v 3D");
    camera = Android3DConnect(localCameraIndex, CAMERA_SUPPORT_MODE_2D);
}
else if (Android43ConnectFuncType Android43Connect = (Android43ConnectFuncType)dlsym(CameraHALHandle, Android43ConnectName))
{
    std::string currentProcName = getProcessName();
    LOGD("Current process name for camera init: %s", currentProcName.c_str());
    camera = Android43Connect(localCameraIndex, String16(currentProcName.c_str()), USE_CALLING_UID);
}
else
{
    dlclose(CameraHALHandle);
    LOGE("Cannot connect to CameraService. Connect method was not found!");
    return NULL;
}

dlclose(CameraHALHandle);

if ( 0 == camera.get() )
{
    LOGE("initCameraConnect: Unable to connect to CameraService\n");
    return 0;
}

Is it a camera HAL bug in Ti omap? Is it fixable? http://answers.opencv.org/question/5524/access-mobile-camera-from-native-c-vs-android/

My device is google glass with Android 4.4.2. The android.mk of native activity is LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_CAMERA_MODULES:=on
#include ../../sdk/native/jni/OpenCV.mk
include ../../OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := native_activity
LOCAL_SRC_FILES := native.cpp
LOCAL_LDLIBS    += -lm -llog -landroid
LOCAL_STATIC_LIBRARIES += android_native_app_glue

include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/native_app_glue)

Getting the camera to work with OpenCV Native Activity Sample

I have managed to compile the Native Activity example in opencv4android. When running it gives a a fatal error.

07-10 22:35:27.694: D/OpenCV::camera(1818): Libraries folder found: /data/app-lib/org.opencv.engine-1/
07-10 22:35:27.694: D/OpenCV::camera(1818): CameraWrapperConnector::connectToLib: folderPath=/data/app-lib/org.opencv.engine-1/
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.3.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.0.3.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.4.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r2.3.3.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.2.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r2.2.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.0.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.1.1.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r3.0.1.so
07-10 22:35:27.694: D/OpenCV::camera(1818): try to load library 'libnative_camera_r4.4.0.so'
07-10 22:35:27.717: D/OpenCV::camera(1818): Loaded library '/data/app-lib/org.opencv.engine-1/libnative_camera_r4.4.0.so'
07-10 22:35:27.717: D/OpenCV_NativeCamera(1818): CameraHandler::initCameraConnect(0x5a839f5d, 0, 0x5ac1df20, 0x0)
07-10 22:35:27.717: D/OpenCV_NativeCamera(1818): Current process name for camera init: org.opencv.samples.NativeActivity
07-10 22:35:27.858: D/OpenCV_NativeCamera(1818): Instantiated new CameraHandler (0x5a839f5d, 0x5ac1df20)
07-10 22:35:27.858: I/OpenCV_NativeCamera(1818): initCameraConnect: [antibanding=auto;antibanding-values=off,auto,50hz,60hz;auto-convergence-mode=frame;auto-convergence-mode-values=;auto-exposure-lock=false;auto-exposure-lock-supported=true;auto-whitebalance-lock=false;auto-whitebalance-lock-supported=true;awb-damping=false;brightness=50;camera-name=S5K4E1GA;contrast=100;current-iso=100;effect=none;effect-values=none,negative,solarize,sepia,mono,natural,vivid,color-swap,blackwhite,whiteboard,blackboard,aqua,posterize;exif-image-description=;exif-make=Google;exif-model=Glass 1;exif-software=Glass-1 XE18.11 1223935;exposure=auto;exposure-compensation=0;exposure-compensation-step=0.1;exposure-mode-values=manual,auto,night,backlighting,spotlight,sports,snow,beach,aperture,small-aperture;flash-mode=off;flash-mode-values=off;focal-length=2.95;focus-mode=infinity;focus-mode-values=infinity;gbce=false;gbce-supported=true;glbce=false;glbce-supported=true;horizontal-view-angle=54.8;ipp=ldc-nsf;ipp-values=off,ldc,nsf,
ldc-nsf;iso=auto;iso-mode-values=auto,100,200,400,
07-10 22:35:27.858: D/OpenCV_NativeCamera(1818): Supported Cameras: (null)
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Picture Sizes: 2592x1944,2560x1888,2528x1856,2592x1728,2592x1458,2560x1888,2400x1350,2304x1296,2240x1344,2160x1440,2112x1728,2112x1188,2048x1152,2048x1536,2016x1512,2016x1134,2000x1600,1920x1080,1600x1200,1600x900,1536x864,1408x792,1344x756,1296x972,1280x1024,1280x720,1152x864,1280x960,1024x768,1024x576,640x480,320x240
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Picture Formats: unused,yuv420sp,yuv420p,yuv422i-yuyv,rgb565,bayer-rggb,jpeg
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Preview Sizes: 1920x1080,1280x960,1280x720,1024x768,1024x576,960x720,800x480,768x576,720x576,720x480,768x576,640x480,640x368,640x360,512x384,512x288,416x304,416x240,352x288,320x240,320x192,256x144,240x160,224x160,176x144,160x120,128x96,960x1280,720x1280,768x1024,576x1024,720x960,480x800,576x768,576x720,576x768,480x720,480x640,368x640,384x512,288x512,304x416,240x416,288x352,240x320,192x320,144x256,160x240,160x224,144x176,120x160,96x128
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Preview Formats: yuv420sp,yuv420p,yuv422i-yuyv,yuv420p
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Preview Frame Rates: 5,10,15,20,24,30,60
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Thumbnail Sizes: 640x480,160x120,200x120,320x240,512x384,352x144,176x144,96x96,0x0
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Whitebalance Modes: auto,daylight,cloudy-daylight,tungsten,fluorescent,incandescent,horizon,sunset,shade,twilight,warm-fluorescent
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Effects: none,negative,solarize,sepia,mono,natural,vivid,color-swap,blackwhite,whiteboard,blackboard,aqua,posterize
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Scene Modes: auto,closeup,landscape,aqua,sports,mood,night-portrait,night-indoor,fireworks,document,barcode,super-night,cine,old-film,action,beach,candlelight,night,party,portrait,snow,steadyphoto,sunset,theatre
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Focus Modes: infinity
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Antibanding Options: off,auto,50hz,60hz
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Flash Modes: off
07-10 22:35:27.881: D/OpenCV_NativeCamera(1818): initCameraConnect: preview format is set to yuv420sp
07-10 22:35:27.889: D/OpenCV_NativeCamera(1818): initCameraConnect: preview format is set to 640x480
07-10 22:35:27.889: A/libc(1818): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 1885 (.NativeActivity)

After that I built the libnative_camera interface from scratch using the opencv source (linux download) (http://code.opencv.org/projects/opencv/wiki/Building_OpenCV4Android_from_trunk). It gives a camera opening error.

07-11 07:06:23.430: I/OCV:libnative_activity(20023): APP_CMD_INIT_WINDOW
07-11 07:06:23.430: D/OpenCV::camera(20023): CvCapture_Android::CvCapture_Android(0)
07-11 07:06:23.437: D/OpenCV::camera(20023): Library name: libopencv_java.so
07-11 07:06:23.437: D/OpenCV::camera(20023): Library base address: 0x591ae000
07-11 07:06:23.539: D/OpenCV::camera(20023): Libraries folder found: /data/app-lib/org.opencv.engine-1/
07-11 07:06:23.539: D/OpenCV::camera(20023): CameraWrapperConnector::connectToLib: folderPath=/data/app-lib/org.opencv.engine-1/
07-11 07:06:23.539: E/OpenCV::camera(20023): ||libnative_camera_r4.3.0.so
07-11 07:06:23.539: E/OpenCV::camera(20023): ||libnative_camera_r4.0.3.so
07-11 07:06:23.539: E/OpenCV::camera(20023): ||libnative_camera_r4.4.0.so
07-11 07:06:23.539: E/OpenCV::camera(20023): ||libnative_camera_r2.3.3.so
07-11 07:06:23.547: E/OpenCV::camera(20023): ||libnative_camera_r4.2.0.so
07-11 07:06:23.547: E/OpenCV::camera(20023): ||libnative_camera_r2.2.0.so
07-11 07:06:23.547: E/OpenCV::camera(20023): ||libnative_camera_r4.0.0.so
07-11 07:06:23.547: E/OpenCV::camera(20023): ||libnative_camera_r4.1.1.so
07-11 07:06:23.547: E/OpenCV::camera(20023): ||libnative_camera_r3.0.1.so
07-11 07:06:23.547: D/OpenCV::camera(20023): try to load library 'libnative_camera_r4.4.0.so'
07-11 07:06:23.570: D/OpenCV::camera(20023): Loaded library '/data/app-lib/org.opencv.engine-1/libnative_camera_r4.4.0.so'
07-11 07:06:23.586: D/OpenCV_NativeCamera(20023): CameraHandler::initCameraConnect(0x598d4f5d, 0, 0x5acc2658, 0x0)
07-11 07:06:23.586: D/OpenCV_NativeCamera(20023): Current process name for camera init: org.opencv.samples.NativeActivity
07-11 07:06:24.094: W/CameraBase(20023): An error occurred while connecting to camera: 0
07-11 07:06:24.094: E/OpenCV_NativeCamera(20023): initCameraConnect: Unable to connect to CameraService
07-11 07:06:24.094: E/OpenCV::camera(20023): CameraWrapperConnector::connectWrapper ERROR: the initializing function returned false
07-11 07:06:24.094: E/OpenCV::camera(20023): Native_camera returned opening error: 6
07-11 07:06:24.094: I/OCV:libnative_activity(20023): Here1
07-11 07:06:24.101: E/OCV:libnative_activity(20023): Cannot get supported camera camera_resolutions
07-11 07:06:24.101: I/OCV:libnative_activity(20023): Here2
07-11 07:06:24.101: I/OCV:libnative_activity(20023): Camera initialized at resolution 640x360

That error lines was traced to opencv-2.4.9/modules/androidcamera/camera_wrapper/camera_wrapper.cpp line 521- 555.

if (Android22ConnectFuncType Android22Connect = (Android22ConnectFuncType)dlsym(CameraHALHandle, Android22ConnectName))
{
    LOGD("Connecting to CameraService v 2.2");
    camera = Android22Connect();
}
else if (Android23ConnectFuncType Android23Connect = (Android23ConnectFuncType)dlsym(CameraHALHandle, Android23ConnectName))
{
    LOGD("Connecting to CameraService v 2.3");
    camera = Android23Connect(localCameraIndex);
}
else if (Android3DConnectFuncType Android3DConnect = (Android3DConnectFuncType)dlsym(CameraHALHandle, Android3DConnectName))
{
    LOGD("Connecting to CameraService v 3D");
    camera = Android3DConnect(localCameraIndex, CAMERA_SUPPORT_MODE_2D);
}
else if (Android43ConnectFuncType Android43Connect = (Android43ConnectFuncType)dlsym(CameraHALHandle, Android43ConnectName))
{
    std::string currentProcName = getProcessName();
    LOGD("Current process name for camera init: %s", currentProcName.c_str());
    camera = Android43Connect(localCameraIndex, String16(currentProcName.c_str()), USE_CALLING_UID);
}
else
{
    dlclose(CameraHALHandle);
    LOGE("Cannot connect to CameraService. Connect method was not found!");
    return NULL;
}

dlclose(CameraHALHandle);

if ( 0 == camera.get() )
{
    LOGE("initCameraConnect: Unable to connect to CameraService\n");
    return 0;
}

Is it a camera HAL bug in Ti omap? Is it fixable? fixable? Or is there simple working native camera example that accesses the camera HAL directly? http://answers.opencv.org/question/5524/access-mobile-camera-from-native-c-vs-android/

My device is google glass with Android 4.4.2. The android.mk of native activity is LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_CAMERA_MODULES:=on
#include ../../sdk/native/jni/OpenCV.mk
include ../../OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := native_activity
LOCAL_SRC_FILES := native.cpp
LOCAL_LDLIBS    += -lm -llog -landroid
LOCAL_STATIC_LIBRARIES += android_native_app_glue

include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/native_app_glue)

Getting the camera to work with OpenCV Native Activity Sample

I have managed to compile the Native Activity example in opencv4android. When running it gives a a fatal error.

07-10 22:35:27.694: D/OpenCV::camera(1818): Libraries folder found: /data/app-lib/org.opencv.engine-1/
07-10 22:35:27.694: D/OpenCV::camera(1818): CameraWrapperConnector::connectToLib: folderPath=/data/app-lib/org.opencv.engine-1/
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.3.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.0.3.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.4.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r2.3.3.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.2.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r2.2.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.0.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.1.1.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r3.0.1.so
07-10 22:35:27.694: D/OpenCV::camera(1818): try to load library 'libnative_camera_r4.4.0.so'
07-10 22:35:27.717: D/OpenCV::camera(1818): Loaded library '/data/app-lib/org.opencv.engine-1/libnative_camera_r4.4.0.so'
07-10 22:35:27.717: D/OpenCV_NativeCamera(1818): CameraHandler::initCameraConnect(0x5a839f5d, 0, 0x5ac1df20, 0x0)
07-10 22:35:27.717: D/OpenCV_NativeCamera(1818): Current process name for camera init: org.opencv.samples.NativeActivity
07-10 22:35:27.858: D/OpenCV_NativeCamera(1818): Instantiated new CameraHandler (0x5a839f5d, 0x5ac1df20)
07-10 22:35:27.858: I/OpenCV_NativeCamera(1818): initCameraConnect: [antibanding=auto;antibanding-values=off,auto,50hz,60hz;auto-convergence-mode=frame;auto-convergence-mode-values=;auto-exposure-lock=false;auto-exposure-lock-supported=true;auto-whitebalance-lock=false;auto-whitebalance-lock-supported=true;awb-damping=false;brightness=50;camera-name=S5K4E1GA;contrast=100;current-iso=100;effect=none;effect-values=none,negative,solarize,sepia,mono,natural,vivid,color-swap,blackwhite,whiteboard,blackboard,aqua,posterize;exif-image-description=;exif-make=Google;exif-model=Glass 1;exif-software=Glass-1 XE18.11 1223935;exposure=auto;exposure-compensation=0;exposure-compensation-step=0.1;exposure-mode-values=manual,auto,night,backlighting,spotlight,sports,snow,beach,aperture,small-aperture;flash-mode=off;flash-mode-values=off;focal-length=2.95;focus-mode=infinity;focus-mode-values=infinity;gbce=false;gbce-supported=true;glbce=false;glbce-supported=true;horizontal-view-angle=54.8;ipp=ldc-nsf;ipp-values=off,ldc,nsf,
ldc-nsf;iso=auto;iso-mode-values=auto,100,200,400,
07-10 22:35:27.858: D/OpenCV_NativeCamera(1818): Supported Cameras: (null)
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Picture Sizes: 2592x1944,2560x1888,2528x1856,2592x1728,2592x1458,2560x1888,2400x1350,2304x1296,2240x1344,2160x1440,2112x1728,2112x1188,2048x1152,2048x1536,2016x1512,2016x1134,2000x1600,1920x1080,1600x1200,1600x900,1536x864,1408x792,1344x756,1296x972,1280x1024,1280x720,1152x864,1280x960,1024x768,1024x576,640x480,320x240
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Picture Formats: unused,yuv420sp,yuv420p,yuv422i-yuyv,rgb565,bayer-rggb,jpeg
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Preview Sizes: 1920x1080,1280x960,1280x720,1024x768,1024x576,960x720,800x480,768x576,720x576,720x480,768x576,640x480,640x368,640x360,512x384,512x288,416x304,416x240,352x288,320x240,320x192,256x144,240x160,224x160,176x144,160x120,128x96,960x1280,720x1280,768x1024,576x1024,720x960,480x800,576x768,576x720,576x768,480x720,480x640,368x640,384x512,288x512,304x416,240x416,288x352,240x320,192x320,144x256,160x240,160x224,144x176,120x160,96x128
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Preview Formats: yuv420sp,yuv420p,yuv422i-yuyv,yuv420p
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Preview Frame Rates: 5,10,15,20,24,30,60
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Thumbnail Sizes: 640x480,160x120,200x120,320x240,512x384,352x144,176x144,96x96,0x0
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Whitebalance Modes: auto,daylight,cloudy-daylight,tungsten,fluorescent,incandescent,horizon,sunset,shade,twilight,warm-fluorescent
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Effects: none,negative,solarize,sepia,mono,natural,vivid,color-swap,blackwhite,whiteboard,blackboard,aqua,posterize
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Scene Modes: auto,closeup,landscape,aqua,sports,mood,night-portrait,night-indoor,fireworks,document,barcode,super-night,cine,old-film,action,beach,candlelight,night,party,portrait,snow,steadyphoto,sunset,theatre
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Focus Modes: infinity
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Antibanding Options: off,auto,50hz,60hz
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Flash Modes: off
07-10 22:35:27.881: D/OpenCV_NativeCamera(1818): initCameraConnect: preview format is set to yuv420sp
07-10 22:35:27.889: D/OpenCV_NativeCamera(1818): initCameraConnect: preview format is set to 640x480
07-10 22:35:27.889: A/libc(1818): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 1885 (.NativeActivity)

After that I built the libnative_camera interface from scratch using the opencv source (linux download) (http://code.opencv.org/projects/opencv/wiki/Building_OpenCV4Android_from_trunk). It gives a camera opening the same fatal error.

07-11 07:06:23.430: I/OCV:libnative_activity(20023): APP_CMD_INIT_WINDOW
07-11 07:06:23.430: D/OpenCV::camera(20023): CvCapture_Android::CvCapture_Android(0)
07-11 07:06:23.437: D/OpenCV::camera(20023): Library name: libopencv_java.so
07-11 07:06:23.437: D/OpenCV::camera(20023): Library base address: 0x591ae000
07-11 07:06:23.539: D/OpenCV::camera(20023): Libraries folder found: /data/app-lib/org.opencv.engine-1/
07-11 07:06:23.539: D/OpenCV::camera(20023): CameraWrapperConnector::connectToLib: folderPath=/data/app-lib/org.opencv.engine-1/
07-11 07:06:23.539: E/OpenCV::camera(20023): ||libnative_camera_r4.3.0.so
07-11 07:06:23.539: E/OpenCV::camera(20023): ||libnative_camera_r4.0.3.so
07-11 07:06:23.539: E/OpenCV::camera(20023): ||libnative_camera_r4.4.0.so
07-11 07:06:23.539: E/OpenCV::camera(20023): ||libnative_camera_r2.3.3.so
07-11 07:06:23.547: E/OpenCV::camera(20023): ||libnative_camera_r4.2.0.so
07-11 07:06:23.547: E/OpenCV::camera(20023): ||libnative_camera_r2.2.0.so
07-11 07:06:23.547: E/OpenCV::camera(20023): ||libnative_camera_r4.0.0.so
07-11 07:06:23.547: E/OpenCV::camera(20023): ||libnative_camera_r4.1.1.so
07-11 07:06:23.547: E/OpenCV::camera(20023): ||libnative_camera_r3.0.1.so
07-11 07:06:23.547: D/OpenCV::camera(20023): try to load library 'libnative_camera_r4.4.0.so'
07-11 07:06:23.570: D/OpenCV::camera(20023): Loaded library '/data/app-lib/org.opencv.engine-1/libnative_camera_r4.4.0.so'
07-11 07:06:23.586: D/OpenCV_NativeCamera(20023): CameraHandler::initCameraConnect(0x598d4f5d, 0, 0x5acc2658, 0x0)
07-11 07:06:23.586: D/OpenCV_NativeCamera(20023): Current process name for camera init: org.opencv.samples.NativeActivity
07-11 07:06:24.094: W/CameraBase(20023): An error occurred while connecting to camera: 0
07-11 07:06:24.094: E/OpenCV_NativeCamera(20023): initCameraConnect: Unable to connect to CameraService
07-11 07:06:24.094: E/OpenCV::camera(20023): CameraWrapperConnector::connectWrapper ERROR: the initializing function returned false
07-11 07:06:24.094: E/OpenCV::camera(20023): Native_camera returned opening error: 6
07-11 07:06:24.094: I/OCV:libnative_activity(20023): Here1
07-11 07:06:24.101: E/OCV:libnative_activity(20023): Cannot get supported camera camera_resolutions
07-11 07:06:24.101: I/OCV:libnative_activity(20023): Here2
07-11 07:06:24.101: I/OCV:libnative_activity(20023): Camera initialized at resolution 640x360

That error lines was traced to opencv-2.4.9/modules/androidcamera/camera_wrapper/camera_wrapper.cpp line 521- 555.684- 690.

if (Android22ConnectFuncType Android22Connect void* buffer_queue_obj = (Android22ConnectFuncType)dlsym(CameraHALHandle, Android22ConnectName))
{
    LOGD("Connecting to CameraService v 2.2");
    camera operator new(sizeof(BufferQueue) + MAGIC_TAIL);
handler->queue = Android22Connect();
}
else if (Android23ConnectFuncType Android23Connect new(buffer_queue_obj) BufferQueue();
void* consumer_listener_obj = (Android23ConnectFuncType)dlsym(CameraHALHandle, Android23ConnectName))
{
    LOGD("Connecting to CameraService v 2.3");
    camera operator new(sizeof(ConsumerListenerStub) + MAGIC_TAIL);
handler->listener = Android23Connect(localCameraIndex);
}
else if (Android3DConnectFuncType Android3DConnect new(consumer_listener_obj) ConsumerListenerStub();
handler->queue->consumerConnect(handler->listener, true);
bufferStatus = (Android3DConnectFuncType)dlsym(CameraHALHandle, Android3DConnectName))
{
    LOGD("Connecting to CameraService v 3D");
    camera = Android3DConnect(localCameraIndex, CAMERA_SUPPORT_MODE_2D);
}
else if (Android43ConnectFuncType Android43Connect = (Android43ConnectFuncType)dlsym(CameraHALHandle, Android43ConnectName))
{
    std::string currentProcName = getProcessName();
    LOGD("Current process name for camera init: %s", currentProcName.c_str());
    camera = Android43Connect(localCameraIndex, String16(currentProcName.c_str()), USE_CALLING_UID);
}
else
{
    dlclose(CameraHALHandle);
    LOGE("Cannot connect to CameraService. Connect method was not found!");
    return NULL;
}

dlclose(CameraHALHandle);

if ( 0 == camera.get() )
{
    LOGE("initCameraConnect: Unable to connect to CameraService\n");
    return 0;
}
handler->camera->setPreviewTarget(handler->queue);

Is it a camera HAL bug in Ti omap? Is it fixable? Or is there simple working native camera example that accesses the camera HAL directly? http://answers.opencv.org/question/5524/access-mobile-camera-from-native-c-vs-android/

My device is google glass with Android 4.4.2. The android.mk of native activity is LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_CAMERA_MODULES:=on
#include ../../sdk/native/jni/OpenCV.mk
include ../../OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := native_activity
LOCAL_SRC_FILES := native.cpp
LOCAL_LDLIBS    += -lm -llog -landroid
LOCAL_STATIC_LIBRARIES += android_native_app_glue

include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/native_app_glue)
click to hide/show revision 4
retagged

updated 2014-07-14 04:43:41 -0600

berak gravatar image

Getting the camera to work with OpenCV Native Activity Sample

I have managed to compile the Native Activity example in opencv4android. When running it gives a a fatal error.

07-10 22:35:27.694: D/OpenCV::camera(1818): Libraries folder found: /data/app-lib/org.opencv.engine-1/
07-10 22:35:27.694: D/OpenCV::camera(1818): CameraWrapperConnector::connectToLib: folderPath=/data/app-lib/org.opencv.engine-1/
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.3.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.0.3.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.4.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r2.3.3.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.2.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r2.2.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.0.0.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r4.1.1.so
07-10 22:35:27.694: E/OpenCV::camera(1818): ||libnative_camera_r3.0.1.so
07-10 22:35:27.694: D/OpenCV::camera(1818): try to load library 'libnative_camera_r4.4.0.so'
07-10 22:35:27.717: D/OpenCV::camera(1818): Loaded library '/data/app-lib/org.opencv.engine-1/libnative_camera_r4.4.0.so'
07-10 22:35:27.717: D/OpenCV_NativeCamera(1818): CameraHandler::initCameraConnect(0x5a839f5d, 0, 0x5ac1df20, 0x0)
07-10 22:35:27.717: D/OpenCV_NativeCamera(1818): Current process name for camera init: org.opencv.samples.NativeActivity
07-10 22:35:27.858: D/OpenCV_NativeCamera(1818): Instantiated new CameraHandler (0x5a839f5d, 0x5ac1df20)
07-10 22:35:27.858: I/OpenCV_NativeCamera(1818): initCameraConnect: [antibanding=auto;antibanding-values=off,auto,50hz,60hz;auto-convergence-mode=frame;auto-convergence-mode-values=;auto-exposure-lock=false;auto-exposure-lock-supported=true;auto-whitebalance-lock=false;auto-whitebalance-lock-supported=true;awb-damping=false;brightness=50;camera-name=S5K4E1GA;contrast=100;current-iso=100;effect=none;effect-values=none,negative,solarize,sepia,mono,natural,vivid,color-swap,blackwhite,whiteboard,blackboard,aqua,posterize;exif-image-description=;exif-make=Google;exif-model=Glass 1;exif-software=Glass-1 XE18.11 1223935;exposure=auto;exposure-compensation=0;exposure-compensation-step=0.1;exposure-mode-values=manual,auto,night,backlighting,spotlight,sports,snow,beach,aperture,small-aperture;flash-mode=off;flash-mode-values=off;focal-length=2.95;focus-mode=infinity;focus-mode-values=infinity;gbce=false;gbce-supported=true;glbce=false;glbce-supported=true;horizontal-view-angle=54.8;ipp=ldc-nsf;ipp-values=off,ldc,nsf,
ldc-nsf;iso=auto;iso-mode-values=auto,100,200,400,
07-10 22:35:27.858: D/OpenCV_NativeCamera(1818): Supported Cameras: (null)
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Picture Sizes: 2592x1944,2560x1888,2528x1856,2592x1728,2592x1458,2560x1888,2400x1350,2304x1296,2240x1344,2160x1440,2112x1728,2112x1188,2048x1152,2048x1536,2016x1512,2016x1134,2000x1600,1920x1080,1600x1200,1600x900,1536x864,1408x792,1344x756,1296x972,1280x1024,1280x720,1152x864,1280x960,1024x768,1024x576,640x480,320x240
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Picture Formats: unused,yuv420sp,yuv420p,yuv422i-yuyv,rgb565,bayer-rggb,jpeg
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Preview Sizes: 1920x1080,1280x960,1280x720,1024x768,1024x576,960x720,800x480,768x576,720x576,720x480,768x576,640x480,640x368,640x360,512x384,512x288,416x304,416x240,352x288,320x240,320x192,256x144,240x160,224x160,176x144,160x120,128x96,960x1280,720x1280,768x1024,576x1024,720x960,480x800,576x768,576x720,576x768,480x720,480x640,368x640,384x512,288x512,304x416,240x416,288x352,240x320,192x320,144x256,160x240,160x224,144x176,120x160,96x128
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Preview Formats: yuv420sp,yuv420p,yuv422i-yuyv,yuv420p
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Preview Frame Rates: 5,10,15,20,24,30,60
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Thumbnail Sizes: 640x480,160x120,200x120,320x240,512x384,352x144,176x144,96x96,0x0
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Whitebalance Modes: auto,daylight,cloudy-daylight,tungsten,fluorescent,incandescent,horizon,sunset,shade,twilight,warm-fluorescent
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Effects: none,negative,solarize,sepia,mono,natural,vivid,color-swap,blackwhite,whiteboard,blackboard,aqua,posterize
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Scene Modes: auto,closeup,landscape,aqua,sports,mood,night-portrait,night-indoor,fireworks,document,barcode,super-night,cine,old-film,action,beach,candlelight,night,party,portrait,snow,steadyphoto,sunset,theatre
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Focus Modes: infinity
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Antibanding Options: off,auto,50hz,60hz
07-10 22:35:27.866: D/OpenCV_NativeCamera(1818): Supported Flash Modes: off
07-10 22:35:27.881: D/OpenCV_NativeCamera(1818): initCameraConnect: preview format is set to yuv420sp
07-10 22:35:27.889: D/OpenCV_NativeCamera(1818): initCameraConnect: preview format is set to 640x480
07-10 22:35:27.889: A/libc(1818): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 1885 (.NativeActivity)

After that I built the libnative_camera interface from scratch using the opencv source (linux download) (http://code.opencv.org/projects/opencv/wiki/Building_OpenCV4Android_from_trunk). It gives the same fatal error.

That error lines was traced to opencv-2.4.9/modules/androidcamera/camera_wrapper/camera_wrapper.cpp line 684- 690.

void* buffer_queue_obj = operator new(sizeof(BufferQueue) + MAGIC_TAIL);
handler->queue = new(buffer_queue_obj) BufferQueue();
void* consumer_listener_obj = operator new(sizeof(ConsumerListenerStub) + MAGIC_TAIL);
handler->listener = new(consumer_listener_obj) ConsumerListenerStub();
handler->queue->consumerConnect(handler->listener, true);
bufferStatus = handler->camera->setPreviewTarget(handler->queue);

Is it a camera HAL bug in Ti omap? Is it fixable? Or is there simple working native camera example that accesses the camera HAL directly? http://answers.opencv.org/question/5524/access-mobile-camera-from-native-c-vs-android/

My device is google glass with Android 4.4.2. The android.mk of native activity is LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_CAMERA_MODULES:=on
#include ../../sdk/native/jni/OpenCV.mk
include ../../OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := native_activity
LOCAL_SRC_FILES := native.cpp
LOCAL_LDLIBS    += -lm -llog -landroid
LOCAL_STATIC_LIBRARIES += android_native_app_glue

include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/native_app_glue)