ConvertHull Android ndk和Opencv中的参数无效
Invalid arguments in ConvexHull Android ndk and Opencv
我在android应用程序hello-jni.cpp
的jni文件夹中有这个C++OpenCV代码。我只想找到并绘制convexull,但由于hull[i]
,convexhall方法生成了一个错误"无效参数"。如果我投射(vector<point>(hull[i]))
,程序运行并生成以下错误:
libc"0x00000004处的致命信号11(SIGSEGV)(代码=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;
}
}
初始化hull
时
vector<vector<Point> > contours;
vector<vector<Point> > hull(contours.size());
hull
的大小是0
,因为contours
的大小是0。因此,当您访问hull[i]
时,您的访问是越界的。
在findContours
:之后声明hull
findContours(threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
vector<vector<Point> > hull(contours.size());
您也可以简单地将convexHull
称为:
convexHull(contours[i], hull[i]);
由于第三个参数orientation
默认为false,并且当第二个参数为std::vector
时,第四个参数returnPoints
被忽略。
使用THRESH_OTSU
时会忽略thresh
值。
更新
安卓NDK似乎有一些问题。一个简单的解决方法是:
- 禁用无效参数的错误,或者
- 使用以下内容
代码:
Mat mHull;
convexHull(Mat(contours[i]), mHull, false, true);
hull[i].assign(mHull.begin<Point>(), mHull.end<Point>());
相关文章:
- std::cin >>上的参数无效
- 结果失败或多个参数无效
- 错误:一元"*"的类型参数无效(具有"int"):使用 mergesort 计算
- 错误 带有模块的一元"*"(具有"int")的类型参数无效
- 由于调用 std::condition_variable 后参数无效而导致应用程序崩溃
- MPI_Iprobe:RMA 调用中的位移参数无效
- 推力::sort_by_key上的配置参数无效
- windres 致命错误:将输出写入时:参数无效
- 一元'*'的类型参数无效(有双精度)
- C++:传递给 C 运行时函数的参数无效
- 矢量模板参数无效
- 写入 -: 参数无效 } 时出错
- winsock2:recvfrom()函数以错误10022(参数无效)结束
- 模板参数的显式指定参数无效,该参数是 constexpr
- 模板参数无效
- 调用 getter 成员时的参数无效
- 模板模板参数中的参数无效
- 方法调用中的参数无效
- POSIX 计时器:参数无效
- C++类模板是一个模板:模板参数无效