001/* 002 * Copyright (C) Photon Vision. 003 * 004 * This program is free software: you can redistribute it and/or modify 005 * it under the terms of the GNU General Public License as published by 006 * the Free Software Foundation, either version 3 of the License, or 007 * (at your option) any later version. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program. If not, see <https://www.gnu.org/licenses/>. 016 */ 017 018package org.photonvision.vision.opencv; 019 020import org.jetbrains.annotations.Nullable; 021import org.opencv.core.MatOfPoint2f; 022import org.opencv.core.MatOfPoint3f; 023import org.opencv.core.Point; 024 025public class CVShape implements Releasable { 026 public final Contour contour; 027 028 @Nullable public final ContourShape shape; 029 030 public double radius = 0; 031 public Point center = null; 032 033 private MatOfPoint3f customTarget = null; 034 035 private final MatOfPoint2f approxCurve = new MatOfPoint2f(); 036 037 public CVShape(Contour contour, ContourShape shape) { 038 this.contour = contour; 039 this.shape = shape; 040 } 041 042 public CVShape(Contour contour, Point center, double radius) { 043 this(contour, ContourShape.Circle); 044 this.radius = radius; 045 this.center = center; 046 } 047 048 public CVShape(Contour contour, MatOfPoint3f targetPoints) { 049 this.contour = contour; 050 this.shape = ContourShape.Custom; 051 customTarget = targetPoints; 052 } 053 054 public Contour getContour() { 055 return contour; 056 } 057 058 @Override 059 public void release() { 060 if (customTarget != null) customTarget.release(); 061 approxCurve.release(); 062 contour.release(); 063 } 064}