I have built opencv(with ffmpeg) for android arm64-v8a successfully, however, cvCreateCameraCapture return null.
cvCreateFileCapture work well.
I found we need to set the following item for support camera.
-DWITH_V4L=1 -DHAVE_CAMV4L2=ON
Now, v4l have been built in opencv, however, the following interface in cap_libv4l.cpp can not open device successfully.
static void icvInitCapture_V4L() {
...
deviceHandle = open(deviceName, O_RDONLY);
...
}
That open function failed because of permission denied.
I modify OpencvFindLibsVideo.cmake as below,think my android app don't have related permission.
However, i add the following setting in AndroidManifest.xml.
...
# --- V4L ---
ocv_clear_vars(HAVE_LIBV4L HAVE_CAMV4L HAVE_CAMV4L2 HAVE_VIDEOIO)
if(WITH_V4L)
if(WITH_LIBV4L)
CHECK_MODULE(libv4l1 HAVE_LIBV4L1)
CHECK_MODULE(libv4l2 HAVE_LIBV4L2)
if(HAVE_LIBV4L1 AND HAVE_LIBV4L2)
set(HAVE_LIBV4L YES)
else()
set(HAVE_LIBV4L NO)
endif()
endif()
CHECK_INCLUDE_FILE(linux/videodev.h HAVE_CAMV4L)
CHECK_INCLUDE_FILE(linux/videodev2.h HAVE_CAMV4L2)
CHECK_INCLUDE_FILE(sys/videoio.h HAVE_VIDEOIO)
set(HAVE_CAMV4L YES)
set(HAVE_CAMV4L2YES)
status(" HAVE_LIBV4L:" ${HAVE_LIBV4L})
status(" HAVE_CAMV4L:" ${HAVE_CAMV4L})
status(" HAVE_CAMV4L2:"${HAVE_CAMV4L2})
status(" HAVE_VIDEOIO:"${HAVE_VIDEOIO})
endif(WITH_V4L)
...
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
And opencv functions are called in a thread in my cmake command as below,
/home/jp003027/cmake-3.13.1-Linux-x86_64/bin/cmake -D WITH_FFMPEG=ON -DWITH_V4L=1 -DHAVE_CAMV4L2=ON -DCMAKE_TOOLCHAIN_FILE=/home/jp003027/android-ndk-r16b/build/cmake/android.toolchain.cmake -DANDROID_NDK=/home/jp003027/android-ndk-r16b/ -DANDROID_NATIVE_API_LEVEL=android-21 -DBUILD_JAVA=OFF -DBUILD_ANDROID_EXAMPLES=OFF -DCMAKE_CXX_FLAGS=-D__STDC_CONSTANT_MACROS -DBUILD_ANDROID_PROJECTS=OFF -DANDROID_STL=c++_shared -DBUILD_SHARED_LIBS=ON -DFFMPEG_INCLUDE_DIR=/home/jp003027/arm64-v8a/include -DCMAKE_INSTALL_PREFIX:PATH=/home/jp003027/opencv-3.1.0/build/out -DANDROID_ABI=arm64-v8a ..
Cmake output as below,
CMake Deprecation Warning at CMakeLists.txt:72 (cmake_policy):
The OLD behavior app.
My app is a service for policy CMP0022 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
CMake Deprecation Warning at CMakeLists.txt:77 (cmake_policy):
The OLD behavior for policy CMP0026 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
CMake Deprecation Warning at CMakeLists.txt:82 (cmake_policy):
The OLD behavior for policy CMP0042 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
CMake Warning at /home/jp003027/android-ndk-r16b/build/cmake/android.toolchain.cmake:63 (message):
Using custom NDK path (ANDROID_NDK is set):
/home/jp003027/android-ndk-r16b/
Call Stack (most recent call first):
build/CMakeFiles/3.13.1/CMakeSystem.cmake:6 (include)
CMakeLists.txt:93 (project)
CMake Warning (dev) at cmake/OpenCVFindLibsVideo.cmake:184:
Syntax Warning in cmake code at column 25
Argument not separated from preceding token by whitespace.
Call Stack (most recent call first):
CMakeLists.txt:536 (include)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at cmake/OpenCVFindLibsVideo.cmake:185:
Syntax Warning in cmake code at column 25
Argument not separated from preceding token by whitespace.
Call Stack (most recent call first):
CMakeLists.txt:536 (include)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Looking for linux/videodev.h
-- Looking for linux/videodev.h - not found
-- Looking for linux/videodev2.h
-- Looking for linux/videodev2.h - found
-- Looking for sys/videoio.h
-- Looking for sys/videoio.h - not found
-- HAVE_LIBV4L:
-- HAVE_CAMV4L: YES
-- HAVE_CAMV4L2: 1
-- HAVE_VIDEOIO:
-- Checking for module 'libavresample'
-- No package 'libavresample' found
-- Looking for /home/jp003027/arm64-v8a/include/libavformat/avformat.h
-- Looking for /home/jp003027/arm64-v8a/include/libavformat/avformat.h - not found
-- Looking for /home/jp003027/arm64-v8a/include/ffmpeg/avformat.h
-- Looking for /home/jp003027/arm64-v8a/include/ffmpeg/avformat.h - not found
-- CUDA compilation is disabled (due to Clang unsupported on your platform).
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- To enable PlantUML support, set PLANTUML_JAR environment variable or pass -DPLANTUML_JAR=<filepath> option to cmake
-- Found PythonInterp: /usr/bin/python2.7 (found suitable version "2.7.6", minimum required is "2.7")
-- Found PythonInterp: /usr/bin/python3.4 (found suitable version "3.4.3", minimum required is "3.4")
-- Found apache ant 1.9.3: /usr/bin/ant
CMake Warning at CMakeLists.txt:570 (message):
OpenCV requires Android SDK tools revision 14 or newer. Otherwise tests
and samples will no be compiled.
11111111111111opencv_highgui3333
--
-- General configuration for OpenCV 3.1.0 =====================================
-- Version control: unknown
--
-- Platform:
-- Host: Linux 3.13.0-24-generic x86_64
-- Target: Android 1 aarch64
-- CMake: 3.13.1
-- CMake generator: Unix Makefiles
-- CMake build tool: /usr/bin/make
-- Configuration: Release
--
-- C/C++:
-- Built as dynamic libs?: YES
-- C++ Compiler: /home/jp003027/android-ndk-r16b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ (ver 3.8)
-- C++ flags (Release): -isystem /home/jp003027/android-ndk-r16b/sysroot/usr/include/aarch64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -D__STDC_CONSTANT_MACROS -fsigned-char -W -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Qunused-arguments -fomit-frame-pointer -fvisibility=hidden -fvisibility-inlines-hidden -O2 -DNDEBUG -DNDEBUG
-- C++ flags (Debug): -isystem /home/jp003027/android-ndk-r16b/sysroot/usr/include/aarch64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -D__STDC_CONSTANT_MACROS -fsigned-char -W -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Qunused-arguments -fomit-frame-pointer -fvisibility=hidden -fvisibility-inlines-hidden -O0 -fno-limit-debug-info -O0 -DDEBUG -D_DEBUG
-- C Compiler: /home/jp003027/android-ndk-r16b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- C flags (Release): -isystem /home/jp003027/android-ndk-r16b/sysroot/usr/include/aarch64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fsigned-char -W -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Qunused-arguments -fomit-frame-pointer -fvisibility=hidden -fvisibility-inlines-hidden -O2 -DNDEBUG -DNDEBUG
-- C flags (Debug): -isystem /home/jp003027/android-ndk-r16b/sysroot/usr/include/aarch64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fsigned-char -W -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Qunused-arguments -fomit-frame-pointer -fvisibility=hidden -fvisibility-inlines-hidden -O0 -fno-limit-debug-info -O0 -DDEBUG -D_DEBUG
-- Linker flags (Release2): -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a --sysroot /home/jp003027/android-ndk-r16b/platforms/android-21/arch-arm64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -L/home/jp003027/android-ndk-r16b/sources/cxx-stl/llvm-libc++/libs/arm64-v8a -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now
-- Linker flags (Debug): -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a --sysroot /home/jp003027/android-ndk-r16b/platforms/android-21/arch-arm64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -L/home/jp003027/android-ndk-r16b/sources/cxx-stl/llvm-libc++/libs/arm64-v8a -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now
-- Precompiled headers: NO
-- Extra dependencies: /home/jp003027/android-ndk-r16b/platforms/android-21/arch-arm64/usr/lib/libz.so avcodec avformat avutil swscale dl m log -L/home/jp003027/arm64-v8a/lib -lavcodec -lavfilter -lavformat -lavutil -lfdk-aac -lswresample -lswscale
-- 3rdparty dependencies: libjpeg libwebp libpng libtiff libjasper IlmImf
--
-- OpenCV modules:
-- To be built: core flann imgproc ml photo video imgcodecs shape videoio highgui objdetect superres ts features2d calib3d java stitching videostab
-- Disabled: world
-- Disabled by dependency: -
-- Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev python2 viz
--
-- Android:
-- Android ABI: arm64-v8a
-- STL type: c++_shared
-- Native API level: android-21
-- SDK target: android_sdk_target_status-NOTFOUND
-- android tool: NO
-- Google Play manager: NO
-- Android examples: NO
--
-- GUI:
-- GTK+: NO
-- GThread : NO
-- GtkGlExt: NO
-- OpenGL support: NO
-- VTK support: NO
--
-- Media I/O:
-- ZLib: /home/jp003027/android-ndk-r16b/platforms/android-21/arch-arm64/usr/lib/libz.so (ver 1.2.3)
-- JPEG: build (ver 90)
-- WEBP: build (ver 0.3.1)
-- PNG: build (ver 1.6.19)
-- TIFF: build (ver 42 - 4.0.2)
-- JPEG 2000: build (ver 1.900.1)
-- OpenEXR: build (ver 1.7.1)
-- GDAL: NO
--
-- Video I/O:
-- FFMPEG: YES (prebuilt binaries)
-- codec: YES (ver 57.89.100)
-- format: YES (ver 57.71.100)
-- util: YES (ver 55.58.100)
-- swscale: YES (ver 4.6.100)
-- resample: NO
-- gentoo-style: YES
-- V4L/V4L2: YES/YES
--
-- Parallel framework: pthreads
--
-- Other third-party libraries:
-- Use IPP: NO
-- Use Eigen: NO
-- Use Cuda: NO
-- Use OpenCL: NO
-- Use custom HAL: NO
--
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 2.7.6)
--
-- Python 3:
-- Interpreter: /usr/bin/python3.4 (ver 3.4.3)
--
-- Python (for build): /usr/bin/python2.7
--
-- Java:
-- ant: /usr/bin/ant (ver 1.9.3)
-- Java wrappers: YES
-- Java tests: NO
--
-- Matlab: NO
--
-- Documentation:
-- Doxygen: NO
-- PlantUML: NO
--
-- Tests and samples:
-- Tests: NO
-- Performance tests: YES
-- C/C++ Examples: NO
--
-- Install path: /home/jp003027/opencv-3.1.0/build/out
--
-- cvconfig.h is in: /home/jp003027/opencv-3.1.0/build
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jp003027/opencv-3.1.0/build
building is completed.
However, after i copy all so files to my project.
That cvCreateCameraCapture still return null.android.
Some dependency is not copied How to fix the permission issue for my project, is it?app?
Or other reason?Any idea?
Change my app to system app?