我是openCV的新手,发现做一些基本的东西真的很困难,所以我非常感谢你的帮助。
我的问题是这样的:
我有一个由地理坐标(纬度,经度)组成的点列表,格式为(49.074454444, 22.72638888889)。这些点形成一个多边形,但是一个凹面,我想要实现的是找到这个多边形的凹壳。
我的想法是使用openCV通过绘制这些点来实现它,而不是使用一些形态学变换作为膨胀和侵蚀,以便这些点形成一个固体区域,而不是使用openCV提供的findContours方法。
我的第一个问题是我的方法对吗?我的意思是这样可以实现吗?
现在我的主要问题是什么。首先,我所有的点仅相差一些第 6 位,我不知道如何正确地将它们“插入”到 Mat 中,因为我相信 Mat 由像素组成,所以行和列(整数)。
我试图做这样的事情:
int matSize = 100;
Size size = new Size(matSize, matSize);
Mat src= Mat.zeros(size, CvType.CV_8UC1);
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
for(int i=0; i<listWithPoints.size(); i++){
Point point = new Point(listWithPoints.get(i).getLatitude(),listWithPoints.get(i).getLongitude());
MatOfPoint matOfPoint = new MatOfPoint(point);
contours.add(matOfPoint);
}
Imgproc.drawContours(src, contours, -1, new Scalar(255, 255, 255),1);
int dillatation_size = 5;
Mat element = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(2*dillatation_size + 1, 2*dillatation_size +1));
Mat dst = Mat.zeros(size, CvType.CV_8UC1);
Imgproc.dilate(src, dst, element);
List<MatOfPoint> cnt = new ArrayList<>();
Mat hierarchy = new Mat();
Imgproc.findContours(dst, cnt, hierarchy,Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);
但实际上在绘制轮廓后它不起作用,只有一个点被标记为 255,它的像素 (49,23) 才有意义。
我的最终目标是取回我的区域船体顶点的地理坐标。
我真的很感激任何帮助。