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.dnn.Model; 010import org.opencv.dnn.Net; 011import org.opencv.dnn.TextRecognitionModel; 012import org.opencv.utils.Converters; 013 014// C++: class TextRecognitionModel 015/** 016 * This class represents high-level API for text recognition networks. 017 * 018 * TextRecognitionModel allows to set params for preprocessing input image. 019 * TextRecognitionModel creates net from file with trained weights and config, 020 * sets preprocessing input, runs forward pass and return recognition result. 021 * For TextRecognitionModel, CRNN-CTC is supported. 022 */ 023public class TextRecognitionModel extends Model { 024 025 protected TextRecognitionModel(long addr) { super(addr); } 026 027 // internal usage only 028 public static TextRecognitionModel __fromPtr__(long addr) { return new TextRecognitionModel(addr); } 029 030 // 031 // C++: cv::dnn::TextRecognitionModel::TextRecognitionModel(Net network) 032 // 033 034 /** 035 * Create Text Recognition model from deep learning network 036 * Call setDecodeType() and setVocabulary() after constructor to initialize the decoding method 037 * @param network Net object 038 */ 039 public TextRecognitionModel(Net network) { 040 super(TextRecognitionModel_0(network.nativeObj)); 041 } 042 043 044 // 045 // C++: cv::dnn::TextRecognitionModel::TextRecognitionModel(string model, string config = "") 046 // 047 048 /** 049 * Create text recognition model from network represented in one of the supported formats 050 * Call setDecodeType() and setVocabulary() after constructor to initialize the decoding method 051 * @param model Binary file contains trained weights 052 * @param config Text file contains network configuration 053 */ 054 public TextRecognitionModel(String model, String config) { 055 super(TextRecognitionModel_1(model, config)); 056 } 057 058 /** 059 * Create text recognition model from network represented in one of the supported formats 060 * Call setDecodeType() and setVocabulary() after constructor to initialize the decoding method 061 * @param model Binary file contains trained weights 062 */ 063 public TextRecognitionModel(String model) { 064 super(TextRecognitionModel_2(model)); 065 } 066 067 068 // 069 // C++: TextRecognitionModel cv::dnn::TextRecognitionModel::setDecodeType(string decodeType) 070 // 071 072 /** 073 * Set the decoding method of translating the network output into string 074 * @param decodeType The decoding method of translating the network output into string, currently supported type: 075 * - {@code "CTC-greedy"} greedy decoding for the output of CTC-based methods 076 * - {@code "CTC-prefix-beam-search"} Prefix beam search decoding for the output of CTC-based methods 077 * @return automatically generated 078 */ 079 public TextRecognitionModel setDecodeType(String decodeType) { 080 return new TextRecognitionModel(setDecodeType_0(nativeObj, decodeType)); 081 } 082 083 084 // 085 // C++: string cv::dnn::TextRecognitionModel::getDecodeType() 086 // 087 088 /** 089 * Get the decoding method 090 * @return the decoding method 091 */ 092 public String getDecodeType() { 093 return getDecodeType_0(nativeObj); 094 } 095 096 097 // 098 // C++: TextRecognitionModel cv::dnn::TextRecognitionModel::setDecodeOptsCTCPrefixBeamSearch(int beamSize, int vocPruneSize = 0) 099 // 100 101 /** 102 * Set the decoding method options for {@code "CTC-prefix-beam-search"} decode usage 103 * @param beamSize Beam size for search 104 * @param vocPruneSize Parameter to optimize big vocabulary search, 105 * only take top {@code vocPruneSize} tokens in each search step, {@code vocPruneSize} <= 0 stands for disable this prune. 106 * @return automatically generated 107 */ 108 public TextRecognitionModel setDecodeOptsCTCPrefixBeamSearch(int beamSize, int vocPruneSize) { 109 return new TextRecognitionModel(setDecodeOptsCTCPrefixBeamSearch_0(nativeObj, beamSize, vocPruneSize)); 110 } 111 112 /** 113 * Set the decoding method options for {@code "CTC-prefix-beam-search"} decode usage 114 * @param beamSize Beam size for search 115 * only take top {@code vocPruneSize} tokens in each search step, {@code vocPruneSize} <= 0 stands for disable this prune. 116 * @return automatically generated 117 */ 118 public TextRecognitionModel setDecodeOptsCTCPrefixBeamSearch(int beamSize) { 119 return new TextRecognitionModel(setDecodeOptsCTCPrefixBeamSearch_1(nativeObj, beamSize)); 120 } 121 122 123 // 124 // C++: TextRecognitionModel cv::dnn::TextRecognitionModel::setVocabulary(vector_string vocabulary) 125 // 126 127 /** 128 * Set the vocabulary for recognition. 129 * @param vocabulary the associated vocabulary of the network. 130 * @return automatically generated 131 */ 132 public TextRecognitionModel setVocabulary(List<String> vocabulary) { 133 return new TextRecognitionModel(setVocabulary_0(nativeObj, vocabulary)); 134 } 135 136 137 // 138 // C++: vector_string cv::dnn::TextRecognitionModel::getVocabulary() 139 // 140 141 /** 142 * Get the vocabulary for recognition. 143 * @return vocabulary the associated vocabulary 144 */ 145 public List<String> getVocabulary() { 146 return getVocabulary_0(nativeObj); 147 } 148 149 150 // 151 // C++: string cv::dnn::TextRecognitionModel::recognize(Mat frame) 152 // 153 154 /** 155 * Given the {@code input} frame, create input blob, run net and return recognition result 156 * @param frame The input image 157 * @return The text recognition result 158 */ 159 public String recognize(Mat frame) { 160 return recognize_0(nativeObj, frame.nativeObj); 161 } 162 163 164 // 165 // C++: void cv::dnn::TextRecognitionModel::recognize(Mat frame, vector_Mat roiRects, vector_string& results) 166 // 167 168 /** 169 * Given the {@code input} frame, create input blob, run net and return recognition result 170 * @param frame The input image 171 * @param roiRects List of text detection regions of interest (cv::Rect, CV_32SC4). ROIs is be cropped as the network inputs 172 * @param results A set of text recognition results. 173 */ 174 public void recognize(Mat frame, List<Mat> roiRects, List<String> results) { 175 Mat roiRects_mat = Converters.vector_Mat_to_Mat(roiRects); 176 recognize_1(nativeObj, frame.nativeObj, roiRects_mat.nativeObj, results); 177 } 178 179 180 @Override 181 protected void finalize() throws Throwable { 182 delete(nativeObj); 183 } 184 185 186 187 // C++: cv::dnn::TextRecognitionModel::TextRecognitionModel(Net network) 188 private static native long TextRecognitionModel_0(long network_nativeObj); 189 190 // C++: cv::dnn::TextRecognitionModel::TextRecognitionModel(string model, string config = "") 191 private static native long TextRecognitionModel_1(String model, String config); 192 private static native long TextRecognitionModel_2(String model); 193 194 // C++: TextRecognitionModel cv::dnn::TextRecognitionModel::setDecodeType(string decodeType) 195 private static native long setDecodeType_0(long nativeObj, String decodeType); 196 197 // C++: string cv::dnn::TextRecognitionModel::getDecodeType() 198 private static native String getDecodeType_0(long nativeObj); 199 200 // C++: TextRecognitionModel cv::dnn::TextRecognitionModel::setDecodeOptsCTCPrefixBeamSearch(int beamSize, int vocPruneSize = 0) 201 private static native long setDecodeOptsCTCPrefixBeamSearch_0(long nativeObj, int beamSize, int vocPruneSize); 202 private static native long setDecodeOptsCTCPrefixBeamSearch_1(long nativeObj, int beamSize); 203 204 // C++: TextRecognitionModel cv::dnn::TextRecognitionModel::setVocabulary(vector_string vocabulary) 205 private static native long setVocabulary_0(long nativeObj, List<String> vocabulary); 206 207 // C++: vector_string cv::dnn::TextRecognitionModel::getVocabulary() 208 private static native List<String> getVocabulary_0(long nativeObj); 209 210 // C++: string cv::dnn::TextRecognitionModel::recognize(Mat frame) 211 private static native String recognize_0(long nativeObj, long frame_nativeObj); 212 213 // C++: void cv::dnn::TextRecognitionModel::recognize(Mat frame, vector_Mat roiRects, vector_string& results) 214 private static native void recognize_1(long nativeObj, long frame_nativeObj, long roiRects_mat_nativeObj, List<String> results); 215 216 // native support for java finalize() 217 private static native void delete(long nativeObj); 218 219}