1
我在Android應用程序hello-jni.cpp
的jni文件夾中有這個C++ OpenCV代碼。我只是想找到並繪製凸起,但由於凸起的方法產生了一個錯誤「無效參數」hull[i]
。如果我投(vector<point>(hull[i]))
程序運行,並生成該錯誤:ConvexHull Android ndk和Opencv中的參數無效
libc "Fatal signal 11 (SIGSEGV) at 0x00000004 (code=1)"
任何幫助,真的很感謝。
#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;
}
}
感謝您response.I沒有你所說的話,但現在該程序運行並生成此錯誤: OpenCV錯誤:聲明失敗(!fixedSize()|| len ==((vector *)v) - > size()/ esz)in virtu al void cv :: _ OutputArray :: create(int,int const *,int,int,bool,int)const,file/hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/core/src/matrix。 CPP,行1489 –
@ elnaz.bfrhn適合我。你的錯誤在哪裏? – Miki
正好在這條線凸Hull(Mat(contour [i]),(vector(hull [i]))); –