ConvexHull Android ndk和Opencv中的参数无效 我在我的Android应用程序JNI文件夹中有这个C++ OpenCV代码,代码> hello JN.CPP。我只想找到并绘制convexhull,但由于hull[I]convexhull方法生成了一个错误“无效参数”。如果我投射(vector(hull[I])),程序将运行并生成此错误:

ConvexHull Android ndk和Opencv中的参数无效 我在我的Android应用程序JNI文件夹中有这个C++ OpenCV代码,代码> hello JN.CPP。我只想找到并绘制convexhull,但由于hull[I]convexhull方法生成了一个错误“无效参数”。如果我投射(vector(hull[I])),程序将运行并生成此错误:,android,c++,opencv,Android,C++,Opencv,libc“0x00000004(代码=1)处的致命信号11(SIGSEGV)” 真的非常感谢你的帮助 #include <jni.h> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <android/log.h> #include <ope

libc“0x00000004(代码=1)处的致命信号11(SIGSEGV)”

真的非常感谢你的帮助

#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);
        }
        retVal = (jint)conv;
        return retVal;
    }
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#定义日志标签“hellojni”
#定义LOGI(…)\uuuuuAndroid\uLog\uPrint(android\uLog\uInfo、log\uTag、VA\uArgs\uuuu)
#定义日志(…)\uuuuuAndroid\uLog\uPrint(android\uLog\uError,log\uTag,\uuuU VA\uArgs\uuuuu)
#定义ORIGCOL2ANDROIDORGCOL CV_BGR2BGRA
使用名称空间std;
使用名称空间cv;
外部“C”{
JNIEXPORT jint JNICALL Java\u com\u elmira\u getconvexhull\u Main Activity\u convertNativeGray(
JNINEV*、jobject、jlong addrRgba、jlong addrGray);
JNIEXPORT jint JNICALL Java\u com\u elmira\u getconvexhull\u Main Activity\u convertNativeGray(
JNINEV*、jobject、jlong addrRgba、jlong addrGray){
Mat&mRgb=*(Mat*)添加RRGBA;
Mat&mGray=*(Mat*)addrGray;
int conv=0;
吉特·雷特瓦尔;
Mat src;Mat src_gray;
src=mRgb;
CVT颜色(src、src_灰色、CV_BGR2灰色);
模糊(src_灰,src_灰,大小(3,3));
Mat src_copy=src.clone();
Mat阈值输出;
矢量等值线;
向量外壳(contours.size());
向量层次;
int thresh=100;
阈值(src_灰度,阈值_输出,阈值,255,阈值|二进制| CV_阈值_大津);
///寻找轮廓
findContours(阈值输出、轮廓、层次、CV树、CV链近似、点(0,0));
__android日志打印(android日志信息,“inmethod”,“大小%d***%d”,等高线.size(),阈值输出.cols);
对于(int i=0;i
初始化
船体时

vector<vector<Point> > contours;
vector<vector<Point> > hull(contours.size());

您也可以简单地调用
convexHull
,如下所示:

 convexHull(contours[i], hull[i]);
因为第三个参数
orientation
默认为false,当第二个参数是
std::vector
时,第四个参数
returnPoints
被忽略


thresh
当您使用
thresh\u OTSU
时,值将被忽略


更新

Android NDK似乎存在一些问题。一个简单的解决方法是:

  • 禁用无效参数的错误,或
  • 使用以下命令
代码:

Mat mHull;
convexHull(Mat(contours[i]), mHull, false, true);
hull[i].assign(mHull.begin<Point>(), mHull.end<Point>());
matmhull;
凸形(Mat(轮廓[i]),mHull,假,真);
hull[i].assign(mHull.begin(),mHull.end());

谢谢你的回复。我按照你说的做了,但是现在程序运行并生成了这个错误:OpenCV错误:在虚拟void cv中断言失败(!fixedSize()| | len==((vector*)v)->size()/esz::_OutputArray::create(int,int const*,int,int,bool,int)const,文件/hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/core/src/matrix.cpp,第1489行正好在这条直线上凸出(Mat(等高线[i]),(向量(外壳[i]);将该行更改为:
convexHull(等高线[i],船体[i])当我写convexHull(轮廓[I],外壳[I]);此错误显示为“无效参数”候选项为:void convxhull(常数cv::_InputArray&,常数cv::_OutputArray&,bool,bool)““瞧!问题解决了@Miki!我照你说的做了,然后禁用无效参数的错误,问题就解决了!伟大的非常感谢!
Mat mHull;
convexHull(Mat(contours[i]), mHull, false, true);
hull[i].assign(mHull.begin<Point>(), mHull.end<Point>());