001// 002// This file is auto-generated. Please don't modify it! 003// 004package org.opencv.dnn; 005 006import java.util.ArrayList; 007import java.util.List; 008import org.opencv.core.Mat; 009import org.opencv.core.MatOfFloat; 010import org.opencv.core.MatOfInt; 011import org.opencv.core.MatOfRect; 012import org.opencv.dnn.DetectionModel; 013import org.opencv.dnn.Model; 014import org.opencv.dnn.Net; 015import org.opencv.utils.Converters; 016 017// C++: class DetectionModel 018/** 019 * This class represents high-level API for object detection networks. 020 * 021 * DetectionModel allows to set params for preprocessing input image. 022 * DetectionModel creates net from file with trained weights and config, 023 * sets preprocessing input, runs forward pass and return result detections. 024 * For DetectionModel SSD, Faster R-CNN, YOLO topologies are supported. 025 */ 026public class DetectionModel extends Model { 027 028 protected DetectionModel(long addr) { super(addr); } 029 030 // internal usage only 031 public static DetectionModel __fromPtr__(long addr) { return new DetectionModel(addr); } 032 033 // 034 // C++: cv::dnn::DetectionModel::DetectionModel(String model, String config = "") 035 // 036 037 /** 038 * Create detection model from network represented in one of the supported formats. 039 * An order of {@code model} and {@code config} arguments does not matter. 040 * @param model Binary file contains trained weights. 041 * @param config Text file contains network configuration. 042 */ 043 public DetectionModel(String model, String config) { 044 super(DetectionModel_0(model, config)); 045 } 046 047 /** 048 * Create detection model from network represented in one of the supported formats. 049 * An order of {@code model} and {@code config} arguments does not matter. 050 * @param model Binary file contains trained weights. 051 */ 052 public DetectionModel(String model) { 053 super(DetectionModel_1(model)); 054 } 055 056 057 // 058 // C++: cv::dnn::DetectionModel::DetectionModel(Net network) 059 // 060 061 /** 062 * Create model from deep learning network. 063 * @param network Net object. 064 */ 065 public DetectionModel(Net network) { 066 super(DetectionModel_2(network.nativeObj)); 067 } 068 069 070 // 071 // C++: DetectionModel cv::dnn::DetectionModel::setNmsAcrossClasses(bool value) 072 // 073 074 /** 075 * nmsAcrossClasses defaults to false, 076 * such that when non max suppression is used during the detect() function, it will do so per-class. 077 * This function allows you to toggle this behaviour. 078 * @param value The new value for nmsAcrossClasses 079 * @return automatically generated 080 */ 081 public DetectionModel setNmsAcrossClasses(boolean value) { 082 return new DetectionModel(setNmsAcrossClasses_0(nativeObj, value)); 083 } 084 085 086 // 087 // C++: bool cv::dnn::DetectionModel::getNmsAcrossClasses() 088 // 089 090 /** 091 * Getter for nmsAcrossClasses. This variable defaults to false, 092 * such that when non max suppression is used during the detect() function, it will do so only per-class 093 * @return automatically generated 094 */ 095 public boolean getNmsAcrossClasses() { 096 return getNmsAcrossClasses_0(nativeObj); 097 } 098 099 100 // 101 // C++: void cv::dnn::DetectionModel::detect(Mat frame, vector_int& classIds, vector_float& confidences, vector_Rect& boxes, float confThreshold = 0.5f, float nmsThreshold = 0.0f) 102 // 103 104 /** 105 * Given the {@code input} frame, create input blob, run net and return result detections. 106 * @param classIds Class indexes in result detection. 107 * @param confidences A set of corresponding confidences. 108 * @param boxes A set of bounding boxes. 109 * @param confThreshold A threshold used to filter boxes by confidences. 110 * @param nmsThreshold A threshold used in non maximum suppression. 111 * @param frame automatically generated 112 */ 113 public void detect(Mat frame, MatOfInt classIds, MatOfFloat confidences, MatOfRect boxes, float confThreshold, float nmsThreshold) { 114 Mat classIds_mat = classIds; 115 Mat confidences_mat = confidences; 116 Mat boxes_mat = boxes; 117 detect_0(nativeObj, frame.nativeObj, classIds_mat.nativeObj, confidences_mat.nativeObj, boxes_mat.nativeObj, confThreshold, nmsThreshold); 118 } 119 120 /** 121 * Given the {@code input} frame, create input blob, run net and return result detections. 122 * @param classIds Class indexes in result detection. 123 * @param confidences A set of corresponding confidences. 124 * @param boxes A set of bounding boxes. 125 * @param confThreshold A threshold used to filter boxes by confidences. 126 * @param frame automatically generated 127 */ 128 public void detect(Mat frame, MatOfInt classIds, MatOfFloat confidences, MatOfRect boxes, float confThreshold) { 129 Mat classIds_mat = classIds; 130 Mat confidences_mat = confidences; 131 Mat boxes_mat = boxes; 132 detect_1(nativeObj, frame.nativeObj, classIds_mat.nativeObj, confidences_mat.nativeObj, boxes_mat.nativeObj, confThreshold); 133 } 134 135 /** 136 * Given the {@code input} frame, create input blob, run net and return result detections. 137 * @param classIds Class indexes in result detection. 138 * @param confidences A set of corresponding confidences. 139 * @param boxes A set of bounding boxes. 140 * @param frame automatically generated 141 */ 142 public void detect(Mat frame, MatOfInt classIds, MatOfFloat confidences, MatOfRect boxes) { 143 Mat classIds_mat = classIds; 144 Mat confidences_mat = confidences; 145 Mat boxes_mat = boxes; 146 detect_2(nativeObj, frame.nativeObj, classIds_mat.nativeObj, confidences_mat.nativeObj, boxes_mat.nativeObj); 147 } 148 149 150 @Override 151 protected void finalize() throws Throwable { 152 delete(nativeObj); 153 } 154 155 156 157 // C++: cv::dnn::DetectionModel::DetectionModel(String model, String config = "") 158 private static native long DetectionModel_0(String model, String config); 159 private static native long DetectionModel_1(String model); 160 161 // C++: cv::dnn::DetectionModel::DetectionModel(Net network) 162 private static native long DetectionModel_2(long network_nativeObj); 163 164 // C++: DetectionModel cv::dnn::DetectionModel::setNmsAcrossClasses(bool value) 165 private static native long setNmsAcrossClasses_0(long nativeObj, boolean value); 166 167 // C++: bool cv::dnn::DetectionModel::getNmsAcrossClasses() 168 private static native boolean getNmsAcrossClasses_0(long nativeObj); 169 170 // C++: void cv::dnn::DetectionModel::detect(Mat frame, vector_int& classIds, vector_float& confidences, vector_Rect& boxes, float confThreshold = 0.5f, float nmsThreshold = 0.0f) 171 private static native void detect_0(long nativeObj, long frame_nativeObj, long classIds_mat_nativeObj, long confidences_mat_nativeObj, long boxes_mat_nativeObj, float confThreshold, float nmsThreshold); 172 private static native void detect_1(long nativeObj, long frame_nativeObj, long classIds_mat_nativeObj, long confidences_mat_nativeObj, long boxes_mat_nativeObj, float confThreshold); 173 private static native void detect_2(long nativeObj, long frame_nativeObj, long classIds_mat_nativeObj, long confidences_mat_nativeObj, long boxes_mat_nativeObj); 174 175 // native support for java finalize() 176 private static native void delete(long nativeObj); 177 178}