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.Scalar; 010import org.opencv.core.Size; 011import org.opencv.dnn.Model; 012import org.opencv.dnn.Net; 013import org.opencv.utils.Converters; 014 015// C++: class Model 016/** 017 * This class is presented high-level API for neural networks. 018 * 019 * Model allows to set params for preprocessing input image. 020 * Model creates net from file with trained weights and config, 021 * sets preprocessing input and runs forward pass. 022 */ 023public class Model { 024 025 protected final long nativeObj; 026 protected Model(long addr) { nativeObj = addr; } 027 028 public long getNativeObjAddr() { return nativeObj; } 029 030 // internal usage only 031 public static Model __fromPtr__(long addr) { return new Model(addr); } 032 033 // 034 // C++: cv::dnn::Model::Model(String model, String config = "") 035 // 036 037 /** 038 * Create model from deep learning 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 Model(String model, String config) { 044 nativeObj = Model_0(model, config); 045 } 046 047 /** 048 * Create model from deep learning 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 Model(String model) { 053 nativeObj = Model_1(model); 054 } 055 056 057 // 058 // C++: cv::dnn::Model::Model(Net network) 059 // 060 061 /** 062 * Create model from deep learning network. 063 * @param network Net object. 064 */ 065 public Model(Net network) { 066 nativeObj = Model_2(network.nativeObj); 067 } 068 069 070 // 071 // C++: Model cv::dnn::Model::setInputSize(Size size) 072 // 073 074 /** 075 * Set input size for frame. 076 * @param size New input size. 077 * <b>Note:</b> If shape of the new blob less than 0, then frame size not change. 078 * @return automatically generated 079 */ 080 public Model setInputSize(Size size) { 081 return new Model(setInputSize_0(nativeObj, size.width, size.height)); 082 } 083 084 085 // 086 // C++: Model cv::dnn::Model::setInputSize(int width, int height) 087 // 088 089 /** 090 * 091 * @param width New input width. 092 * @param height New input height. 093 * @return automatically generated 094 */ 095 public Model setInputSize(int width, int height) { 096 return new Model(setInputSize_1(nativeObj, width, height)); 097 } 098 099 100 // 101 // C++: Model cv::dnn::Model::setInputMean(Scalar mean) 102 // 103 104 /** 105 * Set mean value for frame. 106 * @param mean Scalar with mean values which are subtracted from channels. 107 * @return automatically generated 108 */ 109 public Model setInputMean(Scalar mean) { 110 return new Model(setInputMean_0(nativeObj, mean.val[0], mean.val[1], mean.val[2], mean.val[3])); 111 } 112 113 114 // 115 // C++: Model cv::dnn::Model::setInputScale(Scalar scale) 116 // 117 118 /** 119 * Set scalefactor value for frame. 120 * @param scale Multiplier for frame values. 121 * @return automatically generated 122 */ 123 public Model setInputScale(Scalar scale) { 124 return new Model(setInputScale_0(nativeObj, scale.val[0], scale.val[1], scale.val[2], scale.val[3])); 125 } 126 127 128 // 129 // C++: Model cv::dnn::Model::setInputCrop(bool crop) 130 // 131 132 /** 133 * Set flag crop for frame. 134 * @param crop Flag which indicates whether image will be cropped after resize or not. 135 * @return automatically generated 136 */ 137 public Model setInputCrop(boolean crop) { 138 return new Model(setInputCrop_0(nativeObj, crop)); 139 } 140 141 142 // 143 // C++: Model cv::dnn::Model::setInputSwapRB(bool swapRB) 144 // 145 146 /** 147 * Set flag swapRB for frame. 148 * @param swapRB Flag which indicates that swap first and last channels. 149 * @return automatically generated 150 */ 151 public Model setInputSwapRB(boolean swapRB) { 152 return new Model(setInputSwapRB_0(nativeObj, swapRB)); 153 } 154 155 156 // 157 // C++: void cv::dnn::Model::setInputParams(double scale = 1.0, Size size = Size(), Scalar mean = Scalar(), bool swapRB = false, bool crop = false) 158 // 159 160 /** 161 * Set preprocessing parameters for frame. 162 * @param size New input size. 163 * @param mean Scalar with mean values which are subtracted from channels. 164 * @param scale Multiplier for frame values. 165 * @param swapRB Flag which indicates that swap first and last channels. 166 * @param crop Flag which indicates whether image will be cropped after resize or not. 167 * blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) ) 168 */ 169 public void setInputParams(double scale, Size size, Scalar mean, boolean swapRB, boolean crop) { 170 setInputParams_0(nativeObj, scale, size.width, size.height, mean.val[0], mean.val[1], mean.val[2], mean.val[3], swapRB, crop); 171 } 172 173 /** 174 * Set preprocessing parameters for frame. 175 * @param size New input size. 176 * @param mean Scalar with mean values which are subtracted from channels. 177 * @param scale Multiplier for frame values. 178 * @param swapRB Flag which indicates that swap first and last channels. 179 * blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) ) 180 */ 181 public void setInputParams(double scale, Size size, Scalar mean, boolean swapRB) { 182 setInputParams_1(nativeObj, scale, size.width, size.height, mean.val[0], mean.val[1], mean.val[2], mean.val[3], swapRB); 183 } 184 185 /** 186 * Set preprocessing parameters for frame. 187 * @param size New input size. 188 * @param mean Scalar with mean values which are subtracted from channels. 189 * @param scale Multiplier for frame values. 190 * blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) ) 191 */ 192 public void setInputParams(double scale, Size size, Scalar mean) { 193 setInputParams_2(nativeObj, scale, size.width, size.height, mean.val[0], mean.val[1], mean.val[2], mean.val[3]); 194 } 195 196 /** 197 * Set preprocessing parameters for frame. 198 * @param size New input size. 199 * @param scale Multiplier for frame values. 200 * blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) ) 201 */ 202 public void setInputParams(double scale, Size size) { 203 setInputParams_3(nativeObj, scale, size.width, size.height); 204 } 205 206 /** 207 * Set preprocessing parameters for frame. 208 * @param scale Multiplier for frame values. 209 * blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) ) 210 */ 211 public void setInputParams(double scale) { 212 setInputParams_4(nativeObj, scale); 213 } 214 215 /** 216 * Set preprocessing parameters for frame. 217 * blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) ) 218 */ 219 public void setInputParams() { 220 setInputParams_5(nativeObj); 221 } 222 223 224 // 225 // C++: void cv::dnn::Model::predict(Mat frame, vector_Mat& outs) 226 // 227 228 /** 229 * Given the {@code input} frame, create input blob, run net and return the output {@code blobs}. 230 * @param outs Allocated output blobs, which will store results of the computation. 231 * @param frame automatically generated 232 */ 233 public void predict(Mat frame, List<Mat> outs) { 234 Mat outs_mat = new Mat(); 235 predict_0(nativeObj, frame.nativeObj, outs_mat.nativeObj); 236 Converters.Mat_to_vector_Mat(outs_mat, outs); 237 outs_mat.release(); 238 } 239 240 241 // 242 // C++: Model cv::dnn::Model::setPreferableBackend(dnn_Backend backendId) 243 // 244 245 public Model setPreferableBackend(int backendId) { 246 return new Model(setPreferableBackend_0(nativeObj, backendId)); 247 } 248 249 250 // 251 // C++: Model cv::dnn::Model::setPreferableTarget(dnn_Target targetId) 252 // 253 254 public Model setPreferableTarget(int targetId) { 255 return new Model(setPreferableTarget_0(nativeObj, targetId)); 256 } 257 258 259 @Override 260 protected void finalize() throws Throwable { 261 delete(nativeObj); 262 } 263 264 265 266 // C++: cv::dnn::Model::Model(String model, String config = "") 267 private static native long Model_0(String model, String config); 268 private static native long Model_1(String model); 269 270 // C++: cv::dnn::Model::Model(Net network) 271 private static native long Model_2(long network_nativeObj); 272 273 // C++: Model cv::dnn::Model::setInputSize(Size size) 274 private static native long setInputSize_0(long nativeObj, double size_width, double size_height); 275 276 // C++: Model cv::dnn::Model::setInputSize(int width, int height) 277 private static native long setInputSize_1(long nativeObj, int width, int height); 278 279 // C++: Model cv::dnn::Model::setInputMean(Scalar mean) 280 private static native long setInputMean_0(long nativeObj, double mean_val0, double mean_val1, double mean_val2, double mean_val3); 281 282 // C++: Model cv::dnn::Model::setInputScale(Scalar scale) 283 private static native long setInputScale_0(long nativeObj, double scale_val0, double scale_val1, double scale_val2, double scale_val3); 284 285 // C++: Model cv::dnn::Model::setInputCrop(bool crop) 286 private static native long setInputCrop_0(long nativeObj, boolean crop); 287 288 // C++: Model cv::dnn::Model::setInputSwapRB(bool swapRB) 289 private static native long setInputSwapRB_0(long nativeObj, boolean swapRB); 290 291 // C++: void cv::dnn::Model::setInputParams(double scale = 1.0, Size size = Size(), Scalar mean = Scalar(), bool swapRB = false, bool crop = false) 292 private static native void setInputParams_0(long nativeObj, double scale, double size_width, double size_height, double mean_val0, double mean_val1, double mean_val2, double mean_val3, boolean swapRB, boolean crop); 293 private static native void setInputParams_1(long nativeObj, double scale, double size_width, double size_height, double mean_val0, double mean_val1, double mean_val2, double mean_val3, boolean swapRB); 294 private static native void setInputParams_2(long nativeObj, double scale, double size_width, double size_height, double mean_val0, double mean_val1, double mean_val2, double mean_val3); 295 private static native void setInputParams_3(long nativeObj, double scale, double size_width, double size_height); 296 private static native void setInputParams_4(long nativeObj, double scale); 297 private static native void setInputParams_5(long nativeObj); 298 299 // C++: void cv::dnn::Model::predict(Mat frame, vector_Mat& outs) 300 private static native void predict_0(long nativeObj, long frame_nativeObj, long outs_mat_nativeObj); 301 302 // C++: Model cv::dnn::Model::setPreferableBackend(dnn_Backend backendId) 303 private static native long setPreferableBackend_0(long nativeObj, int backendId); 304 305 // C++: Model cv::dnn::Model::setPreferableTarget(dnn_Target targetId) 306 private static native long setPreferableTarget_0(long nativeObj, int targetId); 307 308 // native support for java finalize() 309 private static native void delete(long nativeObj); 310 311}