在Java中向MatOfPoint变量添加值
我正在尝试将在Java中向MatOfPoint变量添加值,java,opencv,double,getter-setter,Java,Opencv,Double,Getter Setter,我正在尝试将double[][]转换为OpenCV的MatOfPoint。点排序是一个双[4][2],其中有四个点的坐标。 我试过: MatOfPoint sourceMat = new MatOfPoint(); for (int idx = 0; idx < 4; idx++) { (sourceMat.get(idx, 0))[0] = pointsOrdered[idx][0]; (sourceMat.get(idx, 0))[1] = pointsOrdered
double[][]
转换为OpenCV
的MatOfPoint
。点排序是一个双[4][2]
,其中有四个点的坐标。
我试过:
MatOfPoint sourceMat = new MatOfPoint();
for (int idx = 0; idx < 4; idx++) {
(sourceMat.get(idx, 0))[0] = pointsOrdered[idx][0];
(sourceMat.get(idx, 0))[1] = pointsOrdered[idx][1];
}
MatOfPoint sourceMat=new MatOfPoint();
for(intidx=0;idx<4;idx++){
(sourceMat.get(idx,0))[0]=pointsOrdered[idx][0];
(sourceMat.get(idx,0))[1]=pointsOrdered[idx][1];
}
但是sourceMat
值保持不变。
我正在尝试一个接一个地添加值,因为我没有找到其他选项
我能做什么?是否有一种访问和修改
MatOfPoint
变量值的简单方法?org.opencv.core.MatOfPoint
需要org.opencv.core.Point
对象,但它存储点的属性值(x,y)
而不是点
对象本身
如果将排序的double[][]点转换为ArrayList
下面是一个非常复杂的示例答案,它展示了如何将列表/数组/数组列表(选择你的毒药)的使用与问题的真正错误和原因结合起来。“Mat get”方法和“Mat put”方法在使用中被混淆-颠倒
MatOfPoint sourceMat=new MatOfPoint();
sourceMat.fromArray(//如果知道值,建议在编译时进行初始化
新点(151,249.),
新观点(105,272.),
新点(102,318.),
新点(138,337.);
//更改现有数据或放置新数据(如果需要)的方法是,首先设置MatOfPoints的大小
double[]角点=新的double[(int)(sourceMat.channels())];//一个点有两个通道
对于(int idx=0;idx什么是MatOfPoint数据类型,这是OpenCV类型吗?是的,我忘了说,对不起。我已经更新了问题。为什么要使用MatOfPoint?你没有为MatOfPoint使用点类型输入?我需要执行扭曲透视变换。我已经看到Imgproc.getPerspectiveTransform需要MatOfPoint变量e包含空间有序点(我已将其存储在双精度[4][2]中)。那么您的输入值类型必须为点以将x、y存储在MatOfPoint中,请检查我的答案
ArrayList<Point> pointsOrdered = new ArrayList<Point>();
pointsOrdered.add(new Point(xVal, yVal));
...
MatOfPoint sourceMat = new MatOfPoint();
sourceMat.fromList(pointsOrdered);
//your sourceMat is Ready.