opencv-mobile
opencv-mobile copied to clipboard
Can't setup Android properly
Hi friends, I bumped into this project just the other day as I was thinking about ways to make OpenCV smaller in an app that I maintain.
The problem is that I have zero experience with CMake or JNI at all, so the instructions provided in the Readme file aren't sufficent for me.
I have extracted the zip file into my projects src/main/jni. Also created the CMakeLists (that I never had) and added the configuration you provided in the readme, but saw a couple of problems and with some searching I ended up with this:
project(camera)
cmake_minimum_required(VERSION 3.22.1)
set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv-mobile-4.9.0-android/sdk/native/jni)
find_package(OpenCV REQUIRED)
target_link_libraries(camera ${OpenCV_LIBS})
It still doesn't work, but it now complains that
Cannot specify link libraries for target "camera" which is not built by
this project.```
Can anyone offer me a little help? Appreciated! :)
you can follow my cmake file here:
cmake_minimum_required(VERSION 3.4.1)
set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv-mobile-4.9.0-android/sdk/native/jni)
find_package(OpenCV REQUIRED)
if(OpenCV_FOUND)
message("OpenCV found successfully")
include_directories(${OpenCV_INCLUDE_DIRS})
# Link against OpenCV libraries
# target_link_libraries(your_target_library ${OpenCV_LIBRARIES})
else()
message(FATAL_ERROR "OpenCV not found")
endif()
add_library( # Sets the name of the library.
native_lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
../cpp/native_lib.cpp)
# Link your library with OpenCV
target_link_libraries(native_lib ${OpenCV_LIBS})
native_lib.cpp is the c++ file that imports openCV and does things.