繁体   English   中英

将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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM