Ask Your Question
0

svm.save() is not working opencv4android

asked 2017-07-03 08:06:42 -0600

Nani gravatar image

updated 2017-07-05 05:18:58 -0600

I trained the SVM classifier which is working perfectly fine but when I tried to save the classifier, it gave me this error: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 17404. After exploration i thing it seems to be a bug in Opencv 3.10 for Android but I can not find a proper solution. Unanswered question is in here. I use opencv 3.10 for Android, one proposed solution is to downgrade to 2.4 and I do not want to degrade as I have done lots of things using this version.

I would like to update the information here: save() in opencv is inherited from org.opencv.core.algorithms and there is no implementation of the function in the svm html description.

svm.load() also does not work as there is no implementation in Opencv 3.10, so please suggest me to downgrade to 2.4 or not?

Any help is more than appreciated.

edit retag flag offensive close merge delete

Comments

@berak please can you suggest any thing based on the last findings, I tried to access all the functions in Algorithm (getDefaultName(), Clear(), save(), and finalize()) and all of them gave me the same segmentation fault and this can be due to calling functions from wrong places or if there is no constructor. Is there any idea solving this as this is the fourth day of the problem and i can not resolve it?

Nani gravatar imageNani ( 2017-07-05 05:25:09 -0600 )edit

please show exactly , what you've tried, and the outcome.

berak gravatar imageberak ( 2017-07-05 05:34:06 -0600 )edit

I tried to call all the functions in public class Algorithm but all of them gives me SIGSEGV error not only the save() when using SVM:

// C++:  String getDefaultName()
private static native String getDefaultName_0(long nativeObj);

// C++:  void clear()
private static native void clear_0(long nativeObj);

// C++:  void save(String filename)
protected static native void save_0(long nativeObj, String filename);

// native support for java finalize()
private static native void delete(long nativeObj);
Nani gravatar imageNani ( 2017-07-05 05:40:30 -0600 )edit

In the SVM class I also added to add the function save() as in load() but nothing changed.

//javadoc: SVM::save(filepath)
public void save(String filename)
{

    save_0(nativeObj, filename);

    return;
}
Nani gravatar imageNani ( 2017-07-05 05:42:08 -0600 )edit

still researching your 1st examples, but for sure, you cannot simply add a load() function in java, without having a resp. c++ implementation (in opencv_java.so)

berak gravatar imageberak ( 2017-07-05 05:46:22 -0600 )edit

I knew that, I just added the function save( ) again in the SVM class which already exist in org.opencv.core.algorithm but no change. I thought if I add it to the SVM class, it can work as the load function.

Nani gravatar imageNani ( 2017-07-05 06:03:10 -0600 )edit

here is some additional information about the crash:

07-05 13:30:07.298 9699-9699/? A/DEBUG: * * 07-05 13:30:07.299 9699-9699/? A/DEBUG: Build fingerprint: 'samsung/hero2ltexx/hero2lte:7.0/NRD90M/G935FXXU1DQD7:user/release-keys' 07-05 13:30:07.299 9699-9699/? A/DEBUG: Revision: '9' 07-05 13:30:07.299 9699-9699/? A/DEBUG: ABI: 'arm64' 07-05 13:30:07.299 9699-9699/? A/DEBUG: pid: 8798, tid: 8798, name: esar.opencvtest >>> com.example.antesar.opencvtest <<< 07-05 13:30:07.299 9699-9699/? A/DEBUG: signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0x7b00000001 07-05 13:30:07.300 9699-9699/? A/DEBUG: x0 0000007b326cc340 x1 0000007fd02c4580 x2 0000007b00000001 x3 0000007b4114e1b2 07-05 13:30:07.300 9699-9699/? A/DEBUG:

Nani gravatar imageNani ( 2017-07-05 07:37:06 -0600 )edit

@berak One of the solutions I tried is to use opencv 2.4 to train the model because it allow me to save the model to Android sd without any problems and then load the saved model in my previous app which uses opencv3.2 to load the model and do the predictions but i countered this error: OpenCV Error: Assertion failed (samples.cols == var_count && samples.type() == CV_32F) in virtual float cv::ml::SVMImpl::predict(cv::InputArray, cv::OutputArray, int) const, file /build/master_pack-android/opencv/modules/ml/src/svm.cpp, line 1930 ml::predict_10() caught cv::Exception: /build/master_pack-android/opencv/modules/ml/src/svm.cpp:1930: error: (-215) samp Does the saved model using opencv 2.4 differes from opencv 3.2.

Any hints regarding this.

Nani gravatar imageNani ( 2017-07-07 07:01:26 -0600 )edit

2.4 and 3.x models are incompatible, sad as it is. (not a java problem)

berak gravatar imageberak ( 2017-07-07 07:50:38 -0600 )edit

Thanks @berak to save my time. Sadly, I will degrade to version 2.4 as it seems there is no straightforward solutions to save and load svm in opencv 3.x.

Nani gravatar imageNani ( 2017-07-07 08:01:18 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-07-05 05:20:12 -0600

Nani gravatar image

For svm.load(), I upgraded to opencv version 3.2 and I found the required function and it is working fine.

edit flag offensive delete link more

Comments

hello , so u save data at 2.4 and load it at 3.2???? i have same problem to save data at opencv 3.2.0 thanks a lot ..

Allen gravatar imageAllen ( 2017-09-09 02:48:02 -0600 )edit

According to the discussion above, saved model using 2.4 is not compatible with 3.2. My solution was to do everything in 2.4 version.

Nani gravatar imageNani ( 2017-09-11 04:27:19 -0600 )edit

thanks Nani

Allen gravatar imageAllen ( 2017-09-11 09:47:32 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-07-03 08:06:42 -0600

Seen: 485 times

Last updated: Jul 05 '17