我正在开发一个Android应用程序,以从输入图像中找到最大的轮廓。
我在c ++中找到了一个可行的示例。
我试图将其适应我的项目,并且试图创建一个JNI函数以返回结果。
我一直坚持将找到的轮廓列表从JNI返回到Java。
这是我目前无法使用的JNI代码
extern "C"
jobjectArray
Java_com_grimg_coffretpfe_Activities_CompareActivity_getQuadrilateral(
JNIEnv *env,
jobject /* this */,
jlong grayscale,
jlong output) {
Mat* mGray = (cv::Mat*) grayscale;
Mat* mOutput = (cv::Mat*) output;
Mat convexHull_mask(mGray->rows, mGray->cols, CV_8UC1);
convexHull_mask = Scalar(0);
vector<vector<Point>> contours;
findContours(*mGray, contours, RETR_EXTERNAL, CHAIN_APPROX_NONE);
vector<int> indices(contours.size());
iota(indices.begin(), indices.end(), 0);
sort(indices.begin(), indices.end(), [&contours](int lhs, int rhs) {
return contours[lhs].size() > contours[rhs].size();
});
/// Find the convex hull object
vector<vector<Point> >hull(1);
convexHull(Mat(contours[indices[0]]), hull[0], false);
vector<Vec4i> lines;
HoughLinesP(convexHull_mask, lines, 1, CV_PI / 200, 50, 50, 10);
if (lines.size() == 4) // we found the 4 sides
{
vector<Vec3f> params(4);
for (int l = 0; l < 4; l++)
{
params.push_back(calcParams(Point(lines[l][0], lines[l][1]), Point(lines[l][2], lines[l][3])));
}
vector<Point> corners;
for (int i = 0; i < params.size(); i++)
{
for (int j = i; j < params.size(); j++) // j starts at i so we don't have duplicated points
{
Point intersec = findIntersection(params[i], params[j]);
if ((intersec.x > 0) && (intersec.y > 0) && (intersec.x < mGray->cols) && (intersec.y < mGray->rows))
{
cout << "corner: " << intersec << endl;
corners.push_back(intersec);
}
}
}
if (corners.size() == 4) // we have the 4 final corners
{
return(corners);
}
}
return(vector<Point>());
}
返回值错误,如何更改这段代码以返回那些轮廓?