First time here? Check out the FAQ!
Use this:
MatOfPoint2f idx = new MatOfPoint2f(); Core.findNonZero(mask, idx); idx.convertTo(idx, CvType.CV_32FC2); RotatedRect box = Imgproc.minAreaRect(idx);