[英]union of contour in java
Is there an efficient way in opencv/java to compute the union of contour and to get the resulting contour ? opencv/java 中是否有一种有效的方法来计算轮廓的并集并获得结果轮廓?
I have tried with conversion of opencv.contour
to java.awt.geom.Area
, with Core.bitwise_
and, to merge MatOfPoint
to curve and approxPolyDP
, but nothing give the good result.我已经尝试将opencv.contour
转换为java.awt.geom.Area
,使用Core.bitwise_
和,将MatOfPoint
合并到 curve 和approxPolyDP
,但没有给出好的结果。
Is the only way, to use drawContour
for contour1 and contour2 on black image, and then to findContour
?是唯一的方法,在黑色图像drawContour
用于 contour1 和 contour2,然后使用findContour
吗?
One solution is :一种解决方案是:
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.