我想在轮廓周围绘制矩形.我在Python中完美地完成了它但是当我将该代码翻译成android时,应用程序每次都会崩溃.
ImageView im = (ImageView) findViewById(R.id.sampleImageView);
// Bitmap bitmap = ((BitmapDrawable) im.getDrawable()).getBitmap();
Bitmap bitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.room);
Mat src = new Mat();
Utils.bitmapToMat(bitmap, src);
Mat gray = new Mat();
Imgproc.cvtColor(src, gray, Imgproc.COLOR_RGBA2GRAY);
Imgproc.Canny(gray, gray, 50, 200);
Imgproc.threshold(gray, gray, 10, 255, Imgproc.THRESH_OTSU);
List<MatOfPoint> contours = new ArrayList<>();
Mat hierarchy = new Mat();
Imgproc.findContours(gray, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0, 0));
Imgproc.drawContours(src, contours, -1, new Scalar(0, 0, 255), -1);
/********************************/
MatOfPoint2f approxCurve = new MatOfPoint2f();
// For each contour found
for (int …Run Code Online (Sandbox Code Playgroud)