vector<Point> pointsInterest;
Mat_<uchar>::iterator itMask= mask.begin<uchar>();//mask is a Mat
Mat_<uchar>::iterator end= mask.end<uchar>();
for( ; itMask!=end; ++itMask)
if(*itMask==255)
pointsInterest.push_back(itMask.pos());
RotatedRect minRect = minAreaRect(pointsInterest);
我需要java实现代码
答案 0 :(得分:0)
同时我们做同样的事情! :)几天前我在互联网上的某个地方找到了与解决方案类似的问题。
这是解决方案:
ArrayList<Point> pointsInterestList = new ArrayList<Point>();
for (int j = 0; j < mask.rows(); j++) {
for (int k = 0; k < mask.cols(); k++) {
double[] pixel = mask.get(j, k);
if (pixel[0] == 255) {
//add Point of Mat to list of points
Point point = new Point(k, j);
pointsInterestList.add(point);
}
}
}
// System.out.println("PointsInteresedList: "+pointsInterestList);
MatOfPoint2f m2fFromList = new MatOfPoint2f();
m2fFromList.fromList(pointsInterestList); //create MatOfPoint2f from list of points
MatOfPoint2f m2f = new MatOfPoint2f();
m2fFromList.convertTo(m2f, CvType.CV_32FC2); //convert to type of MatOfPoint2f created from list of points
RotatedRect minRect = Imgproc.minAreaRect(m2f);