Ask Your Question

bacci85's profile - activity

2014-10-30 12:58:24 -0600 asked a question link opencv NDK library while compiling code with ndk toolchain

I'm trying to link the Opencv Prebuilt NDK libraries in a sample project composed of just a Makefile and a main.cpp.

The Makefile look like this:

   ANDROID_NDK_ROOT=/home/XXX/libraries/android-ndk-r10c
   CC=${ANDROID_NDK_ROOT}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++

   CFLAGS += --sysroot=${ANDROID_NDK_ROOT}/platforms/android-21/arch-arm
   CFLAGS += -frtti -fexceptions 

   CFLAGS += -I/home/XXX/libraries/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/
   CFLAGS += -I/home/XXX/libraries/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/opencv2

   CFLAGS += -I${ANDROID_NDK_ROOT}/sources/cxx-stl/stlport/stlport
   CFLAGS += -I${ANDROID_NDK_ROOT}/sources/cxx-stl/system/include
   CFLAGS += -I${ANDROID_NDK_ROOT}/platforms/android-21/arch-arm/urs/include

   LDFLAGS += -llog -lm -lz

  LDLIBS += -L/home/XXX/libraries/OpenCV-2.4.10-android-sdk/sdk/native/libs/armeabi-v7a
  LDLIBS += -L/home/XXX/libraries/OpenCV-2.4.10-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a
  LDLIBS += -L${ANDROID_NDK_ROOT}/platforms/android-21/arch-arm/usr/lib
  LDLIBS += -L$(SYSROOT)/usr/lib

  SRCDIR   = src
  INCDIR   = inc
  OBJDIR   = obj

  SOURCES  := $(wildcard $(SRCDIR)/*.cpp)
  INCLUDES := $(wildcard $(INCDIR)/*.h)
  OBJS     := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)

  CFLAGS += -I$(INCDIR)

  EXEC=fastDragon
  ARGS=

  all:$(EXEC)

  $(EXEC):$(OBJS)
      $(CC) $(CFLAGS) -o $(EXEC) $(OBJS) $(LDFLAGS) $(LDLIBS) 

  $(OBJS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
      $(CC) $(CFLAGS) -c $< -o $@

 clean:
    $(RM) $(OBJS) *~ $(EXEC) $(SRCDIR)/*~

the main.cpp looks like this:

    #include "opencv2/opencv.hpp"
    #include "opencv2/opencv_modules.hpp"

   int main (int argc, char** argv){

      cv::Mat test;
      return 0;
   }

The compilation runs ok, but then when the linker tries to link all the libraries I get problems as if the libraries are not the correct one. The output looks like this:

obj/main.o:main.cpp:function main: error: undefined reference to '__cxa_end_cleanup'
obj/main.o:main.cpp:function cv::Mat::~Mat(): error: undefined reference to 'cv::fastFree(void*)'
obj/main.o:main.cpp:function cv::Mat::release(): error: undefined reference to 'cv::Mat::deallocate()'
obj/main.o(.ARM.extab+0x0): error: undefined reference to '__gxx_personality_v0'
collect2: error: ld returned 1 exit status
2013-12-06 06:24:06 -0600 asked a question Random trees persistence issue

I'm trying to implement a random tree classifier (CvRTrees) using Opencv. I succeed implementing it with opencv and it is working.

Then I decided to separate the training part from the classification part. The idea is to save the trained forest and load it back when you want to classify something.

I tried in two different way:

  1. using write and read methods of the super class CvStatModel
  2. using store and load methods of the super class CvStatModel

But results form the older implementation that did not save trees to file are different and worst.

Following code is the implementation of 2nd point:

To store it:

for (unsigned i=0; i<scenes.size(); ++i) {
      char class_fname[50];
      char output[100];
      sprintf(class_fname,"class_%d.xml",i);
      sprintf(output,"class_%d",i);
      //classifiers[i]->save(class_fname,output);
      classifiers[i]->save(class_fname);
    }

To load them back:

 for (unsigned int i = 0; i<CLUSTERING_N_CENTERS;i++){
    char class_fname[50];
    char output[100];
    sprintf(class_fname,"class_%d.xml",i);
    sprintf(output,"class_%d",i);
    classifiers[i] = new CvRTrees();
    //classifiers[i]->load(class_fname,output);
    classifiers[i]->load(class_fname);
  }

I'm using opencv 2.4.6 Does anyone have suggestions on this code?