undefined reference to 'cv::imwrite with Android SDK [closed]

asked 2019-09-18 05:38:29 -0600

updated 2020-10-10 11:57:39 -0600

I'm using CMAKE to build OpenALPR, which uses OpenCV.

My CMakeLists.txt contains, among other, the following statements :

  # Discover OpenCV directory automatically
  find_path(OpenCV_DIR
    NAMES OpenCVConfig.cmake
    HINTS ${CMAKE_SOURCE_DIR}/../libraries/opencv/
    /storage/projects/alpr/libraries/opencv/
    )
  # Opencv Package
  FIND_PACKAGE( OpenCV REQUIRED )

CMake doesn't complain about anything, so I assume OpenCV is found (plus, loads of things are built using OpenCV before the error I'm about to mention).

The instruction I use to build everything :

cmake \
    -DANDROID_TOOLCHAIN=g++ \
    -DCMAKE_TOOLCHAIN_FILE=$NDK_ROOT/build/cmake/android.toolchain.cmake \
    -DANDROID_NDK=$NDK_ROOT \
    -DCMAKE_BUILD_TYPE=Release \
    -DANDROID_PLATFORM=$ANDROID_PLATFORM \
    -DANDROID_ABI="$i" \
    -DANDROID_STL=c++_shared \
    -DANDROID_CPP_FEATURES="rtti exceptions" \
    -DTesseract_INCLUDE_BASEAPI_DIR=$TESSERACT_SRC_DIR/api \
    -DTesseract_INCLUDE_CCSTRUCT_DIR=$TESSERACT_SRC_DIR/ccstruct \
    -DTesseract_INCLUDE_CCMAIN_DIR=$TESSERACT_SRC_DIR/ccmain \
    -DTesseract_INCLUDE_CCUTIL_DIR=$TESSERACT_SRC_DIR/ccutil \
    -DTesseract_LIB=$TESSERACT_LIB_DIR/libtess.so \
    -DLeptonica_LIB=$TESSERACT_LIB_DIR/liblept.so \
    -DOpenCV_DIR=$SCRIPTPATH/../OpenCV-android-sdk/sdk/native/jni \
    -DJAVA_AWT_LIBRARY=$JAVA_AWT_LIBRARY \
    -DJAVA_JVM_LIBRARY=$JAVA_JVM_LIBRARY \
    -DJAVA_INCLUDE_PATH=$JAVA_INCLUDE_PATH \
    -DJAVA_INCLUDE_PATH2=$JAVA_INCLUDE_PATH2 \
    -DJAVA_AWT_INCLUDE_PATH=$JAVA_AWT_INCLUDE_PATH \
    -DPngt_LIB=$TESSERACT_LIB_DIR/libpngt.so \
    -DJpgt_LIB=$TESSERACT_LIB_DIR/libjpgt.so \
    -DJnigraphics_LIB=$NDK_ROOT/platforms/$ANDROID_PLATFORM/arch-$arch/usr/$lib/libjnigraphics.so \
    -DANDROID_ARM_MODE=arm \
    ../../src/

Notice that I use the Android OpenCV SDK v3.4.3. I have an undefined error :

openalpr/src/misc_utilities/prepcharsfortraining.cpp:224: error: undefined reference to 'cv::imwrite(cv::String const&, cv::_InputArray const&, std::__ndk1::vector<int, std::__ndk1::allocator<int> > const&)'

The incriminating file has the following include statements :

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <sys/stat.h>
#include "support/filesystem.h"
#include "../tclap/CmdLine.h"
#include "support/utf8.h"

using namespace std;
using namespace cv;
using namespace alpr;

I can't figure out why imwrite cannot be found. I've tried with Android NDK 20,16 and 14 with no luck

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-10 11:57:55.540804

Comments

I don't understand openALPR is it this?

I can't find any android version

LBerger gravatar imageLBerger ( 2019-09-18 07:20:31 -0600 )edit

Yes, that's it. There is no Android version, you have to build it yourself with the NDK and then import the .SO libraries in an Android project (which is what I'm currently trying to do).

ArthurAttout gravatar imageArthurAttout ( 2019-09-18 07:53:33 -0600 )edit

Mmmmh ..Why does imgproc.hpp under the Android SDK doesn't contain any definition for imread, imwrite, and so on ?

ArthurAttout gravatar imageArthurAttout ( 2019-09-18 08:19:24 -0600 )edit

Yes I think it's better to delete. About android and opencv may this can help you.

I'm not an expert in android but when i want to save an image in java I use Imgcodecs.imwrite with opencv 4.1.2(not Imgproc)

LBerger gravatar imageLBerger ( 2019-09-18 08:20:02 -0600 )edit

There's something that's bugging me. This function should exist, it must be somewhere. My .cpp files refer to it everywhere but I can't find it. And unfortunately, the post you linked didn't improve the situation

ArthurAttout gravatar imageArthurAttout ( 2019-09-18 08:46:26 -0600 )edit
LBerger gravatar imageLBerger ( 2019-09-18 08:52:31 -0600 )edit

Yup, when I download the last Android OpenCV SDK, the header at sdk\native\jni\include\opencv2\imgcodecs\imgcodecs.hpp is empty, with an info that it's legacy (but no new destination).

ArthurAttout gravatar imageArthurAttout ( 2019-09-18 09:19:10 -0600 )edit

When i built opencv for android I have got it

LBerger gravatar imageLBerger ( 2019-09-18 09:37:27 -0600 )edit

Could you show me an import statement that uses this library ?

ArthurAttout gravatar imageArthurAttout ( 2019-09-18 09:48:31 -0600 )edit

doc is here

import org.opencv.imgcodecs.Imgcodecs;

LBerger gravatar imageLBerger ( 2019-09-18 10:01:03 -0600 )edit