凸包上的Java的Android 2.3 opencv的 [英] Convex Hull on Java Android Opencv 2.3
问题描述
请帮帮我,
我有凸包在Android上的一个问题。我使用Java和的OpenCV 2.3
I have a problem for Convex Hull on Android. I use Java and OpenCV 2.3.
在我做了它的Java,我对C ++和Visual Studio 2008年提出的。
Before I made it on Java, I made it on C++ with Visual Studio 2008.
这code能够成功地基于C ++运行。
This code can running successfully on C++.
现在,我想从C ++转换成Java在Android上。而且我发现像强制关闭当我在SDK的Android模拟器运行错误。
Now, i want to convert it from C++ to Java on Android. And I found error like "force close" when i run it on SDK Android simulator.
这是对C ++我的code:
This is my code on C++:
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
drawing = Mat::zeros( canny_output.size(), CV_64F );
/// Find the convex hull object for each contour
vector<vector<Point> > hull ( contours.size() );
for( int i = 0; i < contours.size(); i++ )
{ convexHull( Mat(contours[i]), hull[i], false );
}
for(size_t i = 0; i < contours.size(); i++){
drawContours( drawing, hull, i, Scalar(255, 255, 255), CV_FILLED ); // FILL WHITE COLOR
}
这是在Android上我的code:
And this is my code on Android:
Mat hierarchy = new Mat(img_canny.rows(),img_canny.cols(),CvType.CV_8UC1,new Scalar(0));
List<Mat> contours =new ArrayList<Mat>();
List<Mat> hull = new ArrayList<Mat>(contours.size());
drawing = Mat.zeros(img_canny.size(), im_gray);
Imgproc.findContours(img_dilasi, contours, hierarchy,Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0, 0));
for(int i=0; i<contours.size(); i++){
Imgproc.convexHull(contours.get(i), hull.get(i), false);
}
for(int i=0; i<contours.size(); i++){
Imgproc.drawContours(drawing, hull, i, new Scalar(255.0, 255.0, 255.0), 5);
}
有关你的信息,我做凸包稍加修改我的code。 我填一个颜色内轮廓。
For your info, I did a little modification on Convex Hull at my code. I fill a color inside contour.
任何人都可以帮助我解决我的问题?
Anyone can help me to solve my problem?
我很感激你的帮助。
推荐答案
不具备代表添加评论,只想说这两个答案上面帮助我得到Imgproc.convexHull()的工作为我的用例的东西像这样(2.4.8):
Don't have the rep to add comment, just wanted to say the two answers above helped me get Imgproc.convexHull() working for my use case with something like this (2.4.8):
MatOfPoint mopIn = ...
MatOfInt hull = new MatOfInt();
Imgproc.convexHull(mopIn, hull, false);
MatOfPoint mopOut = new MatOfPoint();
mopOut.create((int)hull.size().height,1,CvType.CV_32SC2);
for(int i = 0; i < hull.size().height ; i++)
{
int index = (int)hull.get(i, 0)[0];
double[] point = new double[] {
mopIn.get(index, 0)[0], mopIn.get(index, 0)[1]
};
mopOut.put(i, 0, point);
}
// do something interesting with mopOut
这篇关于凸包上的Java的Android 2.3 opencv的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!