按x坐标对opencv中的MatOfPoint2f进行排序
创始人
2024-08-22 08:30:28
0

要按照MatOfPoint2f中的点的x坐标对其进行排序,可以使用Collections.sort()方法来实现。下面是一个示例代码:

import org.opencv.core.CvType;
import org.opencv.core.MatOfPoint2f;
import org.opencv.core.Point;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        // 创建一个包含点的MatOfPoint2f对象
        List points = new ArrayList<>();
        points.add(new Point(3, 4));
        points.add(new Point(1, 2));
        points.add(new Point(5, 6));
        points.add(new Point(2, 3));
        MatOfPoint2f matOfPoint2f = new MatOfPoint2f();
        matOfPoint2f.fromList(points);

        // 使用Collections.sort()方法按照x坐标对点进行排序
        Collections.sort(matOfPoint2f.toList(), new PointComparator());

        // 打印排序后的点的x坐标
        for (Point point : matOfPoint2f.toList()) {
            System.out.println(point.x);
        }
    }

    // 定义一个PointComparator类用于比较两个点的x坐标
    static class PointComparator implements Comparator {
        @Override
        public int compare(Point p1, Point p2) {
            return Double.compare(p1.x, p2.x);
        }
    }
}

在上述示例中,我们首先创建一个包含四个点的MatOfPoint2f对象,并使用Collections.sort()方法对其进行排序。为了实现排序,我们定义了一个PointComparator类来比较两个点的x坐标。最后,我们遍历排序后的点列表,并打印每个点的x坐标。

相关内容

热门资讯

黑科技科技(wepoke智能a... 黑科技科技(wepoke智能ai)wepower使用说明书(wepOkE)素来是真的有挂(确实有挂)...
黑科技模拟器(wepoke智能... WePoker透视辅助工具核心要点解析‌,黑科技模拟器(wepoke智能ai)wepoke是机器发牌...
黑科技脚本(wepokeai代... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在这款游戏中打牌都...
黑科技辅助挂(wepoke真的... 黑科技辅助挂(wepoke真的有挂)wepoke 软件(wEPOKE)固有真的有挂(有挂猫腻)-哔哩...
黑科技辅助挂(wepoke黑科... 黑科技辅助挂(wepoke黑科技)wepoke软件透明挂演示(wEpOke)一直真的有挂(真的有挂)...
黑科技app(wepoke真的... 此外,数据分析德州()辅助神器app还具备辅助透视行为开挂功能,通过对客户透明挂的深入研究,你可以了...
黑科技智能ai(wepoke辅... 黑科技智能ai(wepoke辅助插件)wepoke软件透明(WEPOke)先前是有挂(果真有挂)-哔...
黑科技模拟器(wepoke透明... 黑科技模拟器(wepoke透明黑科技)wepoke德州扑克用ai代打(WEPOKE)最初存在有挂(有...
黑科技插件(wepoke辅助插... 黑科技插件(wepoke辅助插件)wepoke软件透明(WEPOke)从来是真的有挂(有挂解惑)-哔...
黑科技美元局(wepoke智能... 黑科技美元局(wepoke智能ai)wepoke辅助真的假的(wepoKE)原先真的有挂(竟然有挂)...