java - java中轮廓的联合
问题描述
在 opencv/java 中是否有一种有效的方法来计算轮廓的并集并获得结果轮廓?
我曾尝试将opencv.contour
to java.awt.geom.Area
、 with Core.bitwise_
and 转换为合并MatOfPoint
到 curve and approxPolyDP
,但没有给出好的结果。
是唯一的方法,drawContour
用于黑色图像上的轮廓 1 和轮廓 2,然后使用findContour
?
解决方案
一种解决方案是:
MatOfPoint contoursIntersection( Mat ref, MatOfPoint cnt1, MatOfPoint cnt2) {
MatOfPoint intersec = new MatOfPoint();
Mat blackImage = new Mat();
ref.copyTo( blackImage);
blackImage.setTo( new Scalar( 0, 0, 0));
List<MatOfPoint> coll = new ArrayList<MatOfPoint>();
coll.add(cnt1);
coll.add(cnt2);
Imgproc.drawContours(blackImage, coll, 0, new Scalar(255,0,0), Core.FILLED);
Imgproc.drawContours(blackImage, coll, 1, new Scalar(255,0,0), Core.FILLED);
//Imgproc.fillPoly( blackImage, coll, new Scalar(0,0,255));
blackImage.copyTo( frameIntersection);
Imgproc.cvtColor( blackImage, blackImage, Imgproc.COLOR_BGR2GRAY);
List<MatOfPoint> contours = new ArrayList< MatOfPoint>();
Mat hierarchy = new Mat();
Imgproc.findContours( blackImage, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE );
System.out.println("===== contoursIntersection > number = " + contours.size());
if (contours.size() == 1) {
intersec = contours.get(0);
}
return intersec;
推荐阅读
- angular - 在移动设备上调试 Angular 应用程序时出现地理位置 API 错误
- json - 如何将两个不同的jq语句的行编织在一起
- azure-application-insights - 在应用程序洞察力中用作会话 ID 的内容
- conv-neural-network - 计算给定输入大小的过滤器的数量和大小
- kubernetes - 服务和节点端口的 k8s 1.10 和 1.13 之间有什么区别吗
- python - 如何检索不是由用户创建的对象?
- python - 读取 csv 文件时如何修复非法换行值
- api - 如何获取 Paypal API V2 的交易 ID
- javascript - 将变量传递给 phalcon 的 volt 模板中的函数
- git - 无法推送新的远程存储库