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.objects;
019
020import java.util.List;
021import org.opencv.core.Mat;
022import org.photonvision.common.configuration.NeuralNetworkModelManager;
023import org.photonvision.vision.opencv.Releasable;
024import org.photonvision.vision.pipe.impl.NeuralNetworkPipeResult;
025
026/**
027 * ObjectDetector lifecycle:
028 *
029 * <ol>
030 *   <li>{@link Model}s are discovered by {@link NeuralNetworkModelManager}
031 *   <li>{@link Model} is selected as a parameter of {@link
032 *       org.photonvision.vision.pipe.impl.ObjectDetectionPipe ObjectDetectionPipe}
033 *   <li>{@link Model#load()} is called to create a ObjectDetector instance
034 *   <li>{@link ObjectDetector#detect(Mat, double, double)} is called to perform object detection
035 *   <li>{@link ObjectDetector#release()} is called to release resources
036 * </ol>
037 */
038public interface ObjectDetector extends Releasable {
039    /** Returns the model that created this ObjectDetector. */
040    public Model getModel();
041
042    /**
043     * Returns the classes that the detector can detect
044     *
045     * @return The classes
046     */
047    public List<String> getClasses();
048
049    /**
050     * Detects objects in the given input image. Preprocessing and postprocessing steps should be
051     * embedded into this call.
052     *
053     * @param in The input image to perform object detection on.
054     * @param nmsThresh The threshold value for non-maximum suppression.
055     * @param boxThresh The threshold value for bounding box detection.
056     * @return A list of NeuralNetworkPipeResult objects representing the detected objects. Returns an
057     *     empty list if the detector is not initialized or if no objects are detected.
058     */
059    public List<NeuralNetworkPipeResult> detect(Mat in, double nmsThresh, double boxThresh);
060}