Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Segfault in convertTo Android OpenCV 2.4.x->3.0

Yesterday I moved my project from OpenCV 2.4 to 3.0. I've tested the code in VisualStudio. Everything works fine, but in Android I'm getting errors when I'm trying to run the code. I've built the library with OpenCL enabled (see code bellow). A simple example app, that does edge detection on CPU/GPU works fine, but the app, which was 2.4.x previously is getting weired errors:

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x9

I'm accessing a Mat comming from Java-Side by its Jlong-Adress:

Mat& I_h_temp = *(Mat*)in_addrRawHolo;

Then I do some conversion:

I_h.convertTo(I_h, CV_64FC1);
sqrt(I_h, I_h);

There is an error comming and the App crashes:

    11-23 07:32:39.191 368-368/? I/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
11-23 07:32:39.191 368-368/? I/DEBUG: UUID: 1c75fc96-14cc-406f-b6d5-c2e129dcc0f3
11-23 07:32:39.191 368-368/? I/DEBUG: Build fingerprint: 'Sony/C6903/C6903:5.1.1/14.6.A.0.368/1533290499:user/release-keys'
11-23 07:32:39.192 368-368/? I/DEBUG: Revision: '0'
11-23 07:32:39.192 368-368/? I/DEBUG: ABI: 'arm'
11-23 07:32:39.192 368-368/? I/DEBUG: pid: 32007, tid: 3898, name: Thread-8533  >>> de.example <<<
11-23 07:32:39.192 368-368/? I/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x9
11-23 07:32:39.209 368-368/? I/DEBUG:     r0 9ed54810  r1 00000002  r2 aed69940  r3 00000005
11-23 07:32:39.209 368-368/? I/DEBUG:     r4 9ed54810  r5 00000000  r6 9eb56b80  r7 aed69938
11-23 07:32:39.210 368-368/? I/DEBUG:     r8 00000005  r9 ffffffff  sl 00040000  fp 00000000
11-23 07:32:39.210 368-368/? I/DEBUG:     ip aed69940  sp ae93c718  lr 00000001  pc 9e420c9c  cpsr a00d0030
11-23 07:32:39.212 368-368/? I/DEBUG:     #00 pc 00170c9c  /data/app/de.example-1/lib/arm/libopencv_java3.so (cv::Mat::create(int, int const*, int)+1291)
11-23 07:32:39.212 368-368/? I/DEBUG:     #01 pc 00186cc3  /data/app/de.example-1/lib/arm/libopencv_java3.so (cv::_OutputArray::create(cv::Size_<int>, int, int, bool, int) const+546)
11-23 07:32:39.212 368-368/? I/DEBUG:     #02 pc 000fc7ab  /data/app/de.example-1/lib/arm/libopencv_java3.so (cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const+314)
11-23 07:32:39.212 368-368/? I/DEBUG:     #03 pc 0009110d  /data/app/de.example-1/lib/arm/libopencv_java3.so (Java_org_opencv_core_Mat_n_1convertTo__JJI+52)

The exact same code works with the old Version. I think there is a problem with the library? I've built it using

set PATH=%PATH%;C:\Users\Bene\Downloads\ninja.exe
mkdir OpenCVCL3
cd OpenCVCL3
cmake -GNinja -DCMAKE_MAKE_PROGRAM="C:/Users/Bene/Downloads/ninja.exe" -DCMAKE_TOOLCHAIN_FILE=C:/opencv3cl/platforms/android/android.toolchain.cmake -DANDROID_ABI="armeabi-v7a with NEON" -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DWITH_OPENCL=YES C:/opencv3cl
path/to/ninja.exe install/strip

My Android.mk

LOCAL_PATH      := $(call my-dir)
LOCAL_PATH_EXT  := $(call my-dir)/../libs/
include $(CLEAR_VARS)

#opencv
OPENCVROOT:= C:/OpenCVCL3/install
OPENCV_CAMERA_MODULES:=off
OPENCV_INSTALL_MODULES:=on
#OPENCV_LIB_TYPE:= STATIC
OPENCV_LIB_TYPE:=SHARED

include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk

LOCAL_ARM_MODE  := arm

LOCAL_MODULE    := native_holo

LOCAL_CFLAGS    += -DANDROID_CL
LOCAL_CFLAGS    += -O3 -ffast-math

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include

LOCAL_SRC_FILES := JNIFresnelPropagator.cpp jni_hologram.cpp cvComplex.cpp common.cpp JNIsuperresolution.cpp jni_superresolution.cpp

LOCAL_LDLIBS    += -llog -lGLESv2 -lEGL
LOCAL_LDLIBS    +=  -ldl -llog -ljnigraphics
LOCAL_LDLIBS    += $(LOCAL_PATH_EXT)libOpenCL.so  

include $(BUILD_SHARED_LIBRARY)

Any ideas?