vector<Point> points;
findNonZero(bin, points);
RotatedRect r = minAreaRect(points);
我已转换为:
MatOfPoint2f points=new MatOfPoint2f();
Core.findNonZero(bin, points); //// findNonZero returns Mat but i have provided MatOfPoint2f
RotatedRect r = Imgproc.minAreaRect( points);
我收到以下错误:
FATAL EXCEPTION: main
CvException [org.opencv.core.CvException: cv::Exception: /builds/master_pack-android/opencv/modules/imgproc/src/convhull.cpp:134: error: (-215) total >= 0 && (depth == CV_32F || depth == CV_32S) in function void cv::convexHull(cv::InputArray, cv::OutputArray, bool, bool)
]
at org.opencv.imgproc.Imgproc.minAreaRect_0(Native Method)
at org.opencv.imgproc.Imgproc.minAreaRect(Imgproc.java:2471)
at com.example.camera.MainActivity.updateImageTable(MainActivity.java:405)
at com.example.camera.MainActivity$GetImages.onPostExecute(MainActivity.java:471)
at com.example.camera.MainActivity$GetImages.onPostExecute(MainActivity.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
请帮我纠正这个问题。感谢
答案 0 :(得分:7)
不确定我是否看到了你想要的东西,但是:
RotatedRect rect = null;
Mat points = Mat.zeros(bin.size(),bin.type());
Core.findNonZero(bin, points);
MatOfPoint mpoints = new MatOfPoint(points);
MatOfPoint2f points2f = new MatOfPoint2f(mpoints.toArray());
if (points2f.rows() > 0) {
rect = Imgproc.minAreaRect(points2f);
}
这将起作用并给出类似的东西(薄白色的东西是rotateRect):