Invali arguments in ConvexHull Android ndk and Opencv

asked 2015-11-13 07:07:58 -0500

Elmira gravatar image

Hello All, I have this C ++ OpenCV code in my jni folder of android application hello-jni.cpp. I just want to find and draw convexhull but cause of hull[i] the convexhull method generate an error "invalid arguments". If I cast (vector<point>(hull[i])) the program run and generate this error :

libc "Fatal signal 11 (SIGSEGV) at 0x00000004 (code=1)"

It's three weeks I'm working on this but I couldn't find solution.

any help really really appreciate .

     #include <jni.h>
   #include <opencv2/core/core.hpp>
   #include <opencv2/highgui/highgui.hpp>
   #include <opencv2/imgproc/imgproc.hpp>
    #include <android/log.h>
    #include <opencv/cv.h>
      #include <vector>
      #include <cmath>
     #include <opencv2/opencv.hpp>
     #include <string.h>
     #include <stdio.h>
      #include <stdlib.h>


   #define  LOG_TAG    "hellojni"
   #define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
   #define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
   #define ORIGCOL2ANDROIDORGCOL CV_BGR2BGRA

   using namespace std;
   using namespace cv;




 extern "C" {


 JNIEXPORT jint JNICALL  Java_com_elmira_getconvexhull_MainActivity_convertNativeGray(
    JNIEnv*, jobject, jlong addrRgba, jlong addrGray);
  JNIEXPORT jint JNICALL  Java_com_elmira_getconvexhull_MainActivity_convertNativeGray(
    JNIEnv*, jobject, jlong addrRgba, jlong addrGray) {

 Mat& mRgb = *(Mat*) addrRgba;
  Mat& mGray = *(Mat*) addrGray;

int conv=0;
jint retVal;


Mat src; Mat src_gray;
    src = mRgb;

    cvtColor(src, src_gray, CV_BGR2GRAY);
    blur(src_gray, src_gray, Size(3, 3));


    Mat src_copy = src.clone();
    Mat threshold_output;
    vector<vector<Point> > contours;
    vector<vector<Point> > hull( contours.size() );
    vector<Vec4i> hierarchy;
     int thresh = 100;

       threshold( src_gray, threshold_output, thresh, 255,  THRESH_BINARY||CV_THRESH_OTSU );

       /// Find contours
       findContours( threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );


    __android_log_print(ANDROID_LOG_INFO, "inmethod", "size %d *** %d", contours.size(),threshold_output.cols);

    for (int i =0; i < contours.size(); i++)
    {

        convexHull( Mat(contours[i]),hull[i],false,false);

    }

    __android_log_print(ANDROID_LOG_INFO, "inmethod", "sizehull %d *** %d*** %d", hull.size(),threshold_output.cols,contours.size());
    Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
    Scalar color = Scalar( 255,0,0 );
    Scalar colorr = Scalar( 0,0,255 );
     for( int i = 0; i< contours.size(); i++ )
          {

          }

    mGray=drawing;
retVal = (jint) conv;

return retVal;

      }
    }
edit retag flag offensive close merge delete