List<MatOfPoint> contour = new ArrayList<MatOfPoint>();
Mat hierarch = new Mat();
//find contours
Imgproc.findContours(gray1, contour, hierarch, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
//itrerate through each contour
for (int Idx = 0; Idx < contours.size(); Idx++) {
double area = Imgproc.contourArea(contours.get(contourIdx));
if (area > largest_area) {
largest_area = (int) area1;
largest_contour_index = Idx;
Rect bounding_rect = Imgproc.boundingRect(contour.get(Idx));
Mat img = ROI.submat(bounding_rect1);
Bitmap resultBitmap = Bitmap.createBitmap(gray.cols(), gray.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(gray, resultBitmap);
((ImageView) findViewById(R.id.imageView)).setImageBitmap(resultBitmap);
}
}
沒有它你腦中,你可以谷歌「OpenCV的作物」? – Piglet
[如何在OpenCV中裁剪CvMat?]可能重複(http://stackoverflow.com/questions/8267191/how-to-crop-a-cvmat-in-opencv) – Piglet