我正在开发涉及一些图像处理的Android应用程序。我正在使用Open CV。我集成了开放式CV,为Java添加了新模块,并集成了原生c ++。我可以在Java中使用该库而没有任何问题。但是在C ++中,我遇到了一些问题。请参阅下面的代码。
//
// Created by iljim on 03/04/2018.
//
#include <jni.h>
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
using namespace std;
using namespace cv;
extern "C"
JNIEXPORT jstring
JNICALL
Java_media_memento_memento_VRPhotoSphereActivity_convertEquiRectToCubeMap(
JNIEnv *env,
jobject /* this */, jlong addrMat, jlong addrNewMat) {
Mat& in = *(Mat*)addrMat;
Mat& face = *(Mat*)addrNewMat;
float faceTransform[6][2] =
{
{0, 0},
{M_PI / 2, 0},
{M_PI, 0},
{-M_PI / 2, 0},
{0, -M_PI / 2},
{0, M_PI / 2}
};
int faceId = 0;
int width = -1;
int height = -1;
float inWidth = in.cols;
float inHeight = in.rows;
// Allocate map
Mat mapx(height, width, CV_32F); //Please pay attention to this line.
}
在上面的代码中,注意行“Mat mapx(height,width,CV_32F);”。当我编写代码时,我没有错误。我可以使用Mat的OpenCV c ++库并导入所需的库。如下所示。没错。
问题是当我运行我的应用程序时,由于我突出显示的行,它在logcat中给出了编译错误。
这是错误。
Information:Gradle tasks [:app:assembleDebug]
C:\Users\iljim\Desktop\OpenCV-3.1.0-android-sdk\OpenCV-android-sdk\sdk\native\jni\include\opencv2\core\mat.inl.hpp
Error:(571) undefined reference to 'cv::fastFree(void*)'
Error:(663) undefined reference to 'cv::Mat::create(int, int const*, int)'
Error:(682) undefined reference to 'cv::Mat::deallocate()'
Error:error: linker command failed with exit code 1 (use -v to see invocation)
C:\Users\iljim\Desktop\memento\memento-android\app\src\main\cpp\cubemap.cpp
Warning:(280, 1) warning: control reaches end of non-void function [-Wreturn-type]
Warning:(280, 1) warning: control reaches end of non-void function [-Wreturn-type]
这是截图
我相信我正确地集成了OpenCV for c ++,这就是为什么当我输入一些使用OpenCV功能并且能够导入OpenCV库的代码时它没有给我任何错误。
这是我的CMakeList文件
# Sets the minimum version of CMake required to build your native library.
# This ensures that a certain set of CMake features is available to
# your build.
cmake_minimum_required(VERSION 3.4.1)
include_directories(C:/Users/iljim/Desktop/OpenCV-3.1.0-android-sdk/OpenCV-android-sdk/sdk/native/jni/include)
add_library( lib_opencv SHARED IMPORTED )
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)
# Specifies a library name, specifies whether the library is STATIC or
# SHARED, and provides relative paths to the source code. You can
# define multiple libraries by adding multiple add_library() commands,
# and CMake builds them for you. When you build your app, Gradle
# automatically packages shared libraries with your APK.
add_library( # Specifies the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp )
add_library( # Specifies the name of the library.
cubemap
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/cubemap.cpp )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because system libraries are included in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
# OpenCV lib
lib_opencv
# Cubemap lib
cubemap
# Links the target library to the log library
# included in the NDK.
${log-lib} )
我的代码出了什么问题?什么可能是错误?我该如何解决?