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

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

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

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

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

  # Discover OpenCV directory automatically
    NAMES OpenCVConfig.cmake
    HINTS ${CMAKE_SOURCE_DIR}/../libraries/opencv/
  # Opencv Package

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 \
    -DCMAKE_TOOLCHAIN_FILE=$NDK_ROOT/build/cmake/android.toolchain.cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DANDROID_ABI="$i" \
    -DANDROID_STL=c++_shared \
    -DANDROID_CPP_FEATURES="rtti exceptions" \
    -DTesseract_LIB=$TESSERACT_LIB_DIR/libtess.so \
    -DLeptonica_LIB=$TESSERACT_LIB_DIR/liblept.so \
    -DOpenCV_DIR=$SCRIPTPATH/../OpenCV-android-sdk/sdk/native/jni \
    -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 \

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


I don't understand openALPR is it this?

I can't find any android version

LBerger gravatar imageLBerger ( 2019-09-18 07:20:31 -0500 )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 -0500 )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 -0500 )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 -0500 )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 -0500 )edit
LBerger gravatar imageLBerger ( 2019-09-18 08:52:31 -0500 )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 -0500 )edit

When i built opencv for android I have got it

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

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

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

doc is here

import org.opencv.imgcodecs.Imgcodecs;

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