opencv c++代码转成java的一些问题
Some problems with converting opencv c++ code into java
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代码的实现
同时我们在做同样的事情! :) 几天前我在互联网上的某个地方发现了类似的解决方案。
解决方法如下:
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);
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代码的实现
同时我们在做同样的事情! :) 几天前我在互联网上的某个地方发现了类似的解决方案。
解决方法如下:
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);