我正在尝试在Android上使用opencv(仅限ndk)。我编译了 armeabi 的 git 存储库的最新源代码。(基于: Building_OpenCV4Android_from_trunk)
但是我收到此错误(使用 ndk 构建):
error: undefined reference to 'cv::Mat::deallocate()'
error: undefined reference to 'cv::fastFree(void*)'
error: undefined reference to 'cv::_OutputArray::_OutputArray(cv::Mat&)'
error: undefined reference to 'cv::Mat::copyTo(cv::_OutputArray const&)'
error: undefined reference to 'cv::Mat::inv(int) const'
简单的测试代码:
cv::Mat testMat = cv::Mat(cv::Matx44d
(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
));
cv::Mat testMatInv = testMat.inv();
我 Android.mk:
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../libs/opencv/include
LOCAL_LDLIBS += -L../../../../libs/opencv/lib/android/armeabi
LOCAL_LDLIBS += -llog -lGLESv2 –lz
LOCAL_STATIC_LIBRARIES := libzip libpng libjpeg freetype
LOCAL_STATIC_LIBRARIES += libopencv_calib3d libopencv_contrib libopencv_core libopencv_features2d libopencv_flann libopencv_highgui libopencv_imgproc libopencv_legacy libopencv_ml libopencv_nonfree libopencv_objdetect libopencv_photo libopencv_stitching libopencv_ts libopencv_video libopencv_videostab
有人知道吗?谢谢
我现在让它工作了。我忘了在 Android.mk 中添加预构建库,如下所示:
#same for all other openCV Libs
LOCAL_MODULE := libopencv_calib3d
LOCAL_SRC_FILES := ../../opencv/lib/android/$(TARGET_ARCH_ABI)/libopencv_calib3d.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
.....
LOCAL_STATIC_LIBRARIES += libopencv_contrib libopencv_legacy libopencv_ml libopencv_stitching libopencv_nonfree libopencv_objdetect libopencv_videostab libopencv_calib3d libopencv_photo libopencv_video libopencv_features2d libopencv_highgui libopencv_androidcamera libopencv_flann libopencv_imgproc libopencv_ts libopencv_core
图书馆的顺序很重要。
尝试:
LOCAL_STATIC_LIBRARIES += libopencv_contrib libopencv_legacy libopencv_ml libopencv_stitching libopencv_nonfree libopencv_objdetect libopencv_videostab libopencv_calib3d libopencv_photo libopencv_video libopencv_features2d libopencv_highgui libopencv_androidcamera libopencv_flann libopencv_imgproc libopencv_core
推荐的方法不是对.mk文件中的所有名称进行硬编码,而是使用OpenCV SDK中的 OpenCV.mk 将OpenCV添加到项目中。(如果您从源代码进行自定义构建,则 OpenCV.mk 在 cmake(并进行安装)步骤生成。