Text.cs 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. #if !UNITY_WSA_10_0
  2. using OpenCVForUnity.CoreModule;
  3. using OpenCVForUnity.UtilsModule;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Runtime.InteropServices;
  7. namespace OpenCVForUnity.TextModule
  8. {
  9. // C++: class Text
  10. public class Text
  11. {
  12. // C++: enum <unnamed>
  13. public const int ERFILTER_NM_RGBLGrad = 0;
  14. public const int ERFILTER_NM_IHSGrad = 1;
  15. public const int OCR_LEVEL_WORD = 0;
  16. public const int OCR_LEVEL_TEXTLINE = 1;
  17. // C++: enum cv.text.classifier_type
  18. public const int OCR_KNN_CLASSIFIER = 0;
  19. public const int OCR_CNN_CLASSIFIER = 1;
  20. // C++: enum cv.text.decoder_mode
  21. public const int OCR_DECODER_VITERBI = 0;
  22. // C++: enum cv.text.erGrouping_Modes
  23. public const int ERGROUPING_ORIENTATION_HORIZ = 0;
  24. public const int ERGROUPING_ORIENTATION_ANY = 1;
  25. // C++: enum cv.text.ocr_engine_mode
  26. public const int OEM_TESSERACT_ONLY = 0;
  27. public const int OEM_CUBE_ONLY = 1;
  28. public const int OEM_TESSERACT_CUBE_COMBINED = 2;
  29. public const int OEM_DEFAULT = 3;
  30. // C++: enum cv.text.page_seg_mode
  31. public const int PSM_OSD_ONLY = 0;
  32. public const int PSM_AUTO_OSD = 1;
  33. public const int PSM_AUTO_ONLY = 2;
  34. public const int PSM_AUTO = 3;
  35. public const int PSM_SINGLE_COLUMN = 4;
  36. public const int PSM_SINGLE_BLOCK_VERT_TEXT = 5;
  37. public const int PSM_SINGLE_BLOCK = 6;
  38. public const int PSM_SINGLE_LINE = 7;
  39. public const int PSM_SINGLE_WORD = 8;
  40. public const int PSM_CIRCLE_WORD = 9;
  41. public const int PSM_SINGLE_CHAR = 10;
  42. //
  43. // C++: Ptr_ERFilter cv::text::createERFilterNM1(Ptr_ERFilter_Callback cb, int thresholdDelta = 1, float minArea = (float)0.00025, float maxArea = (float)0.13, float minProbability = (float)0.4, bool nonMaxSuppression = true, float minProbabilityDiff = (float)0.1)
  44. //
  45. /**
  46. * Create an Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm CITE: Neumann12.
  47. *
  48. * loadClassifierNM1, e.g. from file in samples/cpp/trained_classifierNM1.xml
  49. *
  50. * The component tree of the image is extracted by a threshold increased step by step from 0 to 255,
  51. * incrementally computable descriptors (aspect_ratio, compactness, number of holes, and number of
  52. * horizontal crossings) are computed for each ER and used as features for a classifier which estimates
  53. * the class-conditional probability P(er|character). The value of P(er|character) is tracked using the
  54. * inclusion relation of ER across all thresholds and only the ERs which correspond to local maximum of
  55. * the probability P(er|character) are selected (if the local maximum of the probability is above a
  56. * global limit pmin and the difference between local maximum and local minimum is greater than
  57. * minProbabilityDiff).
  58. * param cb automatically generated
  59. * param thresholdDelta automatically generated
  60. * param minArea automatically generated
  61. * param maxArea automatically generated
  62. * param minProbability automatically generated
  63. * param nonMaxSuppression automatically generated
  64. * param minProbabilityDiff automatically generated
  65. * return automatically generated
  66. */
  67. public static ERFilter createERFilterNM1(ERFilter_Callback cb, int thresholdDelta, float minArea, float maxArea, float minProbability, bool nonMaxSuppression, float minProbabilityDiff)
  68. {
  69. if (cb != null) cb.ThrowIfDisposed();
  70. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM1_10(cb.getNativeObjAddr(), thresholdDelta, minArea, maxArea, minProbability, nonMaxSuppression, minProbabilityDiff)));
  71. }
  72. /**
  73. * Create an Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm CITE: Neumann12.
  74. *
  75. * loadClassifierNM1, e.g. from file in samples/cpp/trained_classifierNM1.xml
  76. *
  77. * The component tree of the image is extracted by a threshold increased step by step from 0 to 255,
  78. * incrementally computable descriptors (aspect_ratio, compactness, number of holes, and number of
  79. * horizontal crossings) are computed for each ER and used as features for a classifier which estimates
  80. * the class-conditional probability P(er|character). The value of P(er|character) is tracked using the
  81. * inclusion relation of ER across all thresholds and only the ERs which correspond to local maximum of
  82. * the probability P(er|character) are selected (if the local maximum of the probability is above a
  83. * global limit pmin and the difference between local maximum and local minimum is greater than
  84. * minProbabilityDiff).
  85. * param cb automatically generated
  86. * param thresholdDelta automatically generated
  87. * param minArea automatically generated
  88. * param maxArea automatically generated
  89. * param minProbability automatically generated
  90. * param nonMaxSuppression automatically generated
  91. * return automatically generated
  92. */
  93. public static ERFilter createERFilterNM1(ERFilter_Callback cb, int thresholdDelta, float minArea, float maxArea, float minProbability, bool nonMaxSuppression)
  94. {
  95. if (cb != null) cb.ThrowIfDisposed();
  96. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM1_11(cb.getNativeObjAddr(), thresholdDelta, minArea, maxArea, minProbability, nonMaxSuppression)));
  97. }
  98. /**
  99. * Create an Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm CITE: Neumann12.
  100. *
  101. * loadClassifierNM1, e.g. from file in samples/cpp/trained_classifierNM1.xml
  102. *
  103. * The component tree of the image is extracted by a threshold increased step by step from 0 to 255,
  104. * incrementally computable descriptors (aspect_ratio, compactness, number of holes, and number of
  105. * horizontal crossings) are computed for each ER and used as features for a classifier which estimates
  106. * the class-conditional probability P(er|character). The value of P(er|character) is tracked using the
  107. * inclusion relation of ER across all thresholds and only the ERs which correspond to local maximum of
  108. * the probability P(er|character) are selected (if the local maximum of the probability is above a
  109. * global limit pmin and the difference between local maximum and local minimum is greater than
  110. * minProbabilityDiff).
  111. * param cb automatically generated
  112. * param thresholdDelta automatically generated
  113. * param minArea automatically generated
  114. * param maxArea automatically generated
  115. * param minProbability automatically generated
  116. * return automatically generated
  117. */
  118. public static ERFilter createERFilterNM1(ERFilter_Callback cb, int thresholdDelta, float minArea, float maxArea, float minProbability)
  119. {
  120. if (cb != null) cb.ThrowIfDisposed();
  121. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM1_12(cb.getNativeObjAddr(), thresholdDelta, minArea, maxArea, minProbability)));
  122. }
  123. /**
  124. * Create an Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm CITE: Neumann12.
  125. *
  126. * loadClassifierNM1, e.g. from file in samples/cpp/trained_classifierNM1.xml
  127. *
  128. * The component tree of the image is extracted by a threshold increased step by step from 0 to 255,
  129. * incrementally computable descriptors (aspect_ratio, compactness, number of holes, and number of
  130. * horizontal crossings) are computed for each ER and used as features for a classifier which estimates
  131. * the class-conditional probability P(er|character). The value of P(er|character) is tracked using the
  132. * inclusion relation of ER across all thresholds and only the ERs which correspond to local maximum of
  133. * the probability P(er|character) are selected (if the local maximum of the probability is above a
  134. * global limit pmin and the difference between local maximum and local minimum is greater than
  135. * minProbabilityDiff).
  136. * param cb automatically generated
  137. * param thresholdDelta automatically generated
  138. * param minArea automatically generated
  139. * param maxArea automatically generated
  140. * return automatically generated
  141. */
  142. public static ERFilter createERFilterNM1(ERFilter_Callback cb, int thresholdDelta, float minArea, float maxArea)
  143. {
  144. if (cb != null) cb.ThrowIfDisposed();
  145. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM1_13(cb.getNativeObjAddr(), thresholdDelta, minArea, maxArea)));
  146. }
  147. /**
  148. * Create an Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm CITE: Neumann12.
  149. *
  150. * loadClassifierNM1, e.g. from file in samples/cpp/trained_classifierNM1.xml
  151. *
  152. * The component tree of the image is extracted by a threshold increased step by step from 0 to 255,
  153. * incrementally computable descriptors (aspect_ratio, compactness, number of holes, and number of
  154. * horizontal crossings) are computed for each ER and used as features for a classifier which estimates
  155. * the class-conditional probability P(er|character). The value of P(er|character) is tracked using the
  156. * inclusion relation of ER across all thresholds and only the ERs which correspond to local maximum of
  157. * the probability P(er|character) are selected (if the local maximum of the probability is above a
  158. * global limit pmin and the difference between local maximum and local minimum is greater than
  159. * minProbabilityDiff).
  160. * param cb automatically generated
  161. * param thresholdDelta automatically generated
  162. * param minArea automatically generated
  163. * return automatically generated
  164. */
  165. public static ERFilter createERFilterNM1(ERFilter_Callback cb, int thresholdDelta, float minArea)
  166. {
  167. if (cb != null) cb.ThrowIfDisposed();
  168. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM1_14(cb.getNativeObjAddr(), thresholdDelta, minArea)));
  169. }
  170. /**
  171. * Create an Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm CITE: Neumann12.
  172. *
  173. * loadClassifierNM1, e.g. from file in samples/cpp/trained_classifierNM1.xml
  174. *
  175. * The component tree of the image is extracted by a threshold increased step by step from 0 to 255,
  176. * incrementally computable descriptors (aspect_ratio, compactness, number of holes, and number of
  177. * horizontal crossings) are computed for each ER and used as features for a classifier which estimates
  178. * the class-conditional probability P(er|character). The value of P(er|character) is tracked using the
  179. * inclusion relation of ER across all thresholds and only the ERs which correspond to local maximum of
  180. * the probability P(er|character) are selected (if the local maximum of the probability is above a
  181. * global limit pmin and the difference between local maximum and local minimum is greater than
  182. * minProbabilityDiff).
  183. * param cb automatically generated
  184. * param thresholdDelta automatically generated
  185. * return automatically generated
  186. */
  187. public static ERFilter createERFilterNM1(ERFilter_Callback cb, int thresholdDelta)
  188. {
  189. if (cb != null) cb.ThrowIfDisposed();
  190. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM1_15(cb.getNativeObjAddr(), thresholdDelta)));
  191. }
  192. /**
  193. * Create an Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm CITE: Neumann12.
  194. *
  195. * loadClassifierNM1, e.g. from file in samples/cpp/trained_classifierNM1.xml
  196. *
  197. * The component tree of the image is extracted by a threshold increased step by step from 0 to 255,
  198. * incrementally computable descriptors (aspect_ratio, compactness, number of holes, and number of
  199. * horizontal crossings) are computed for each ER and used as features for a classifier which estimates
  200. * the class-conditional probability P(er|character). The value of P(er|character) is tracked using the
  201. * inclusion relation of ER across all thresholds and only the ERs which correspond to local maximum of
  202. * the probability P(er|character) are selected (if the local maximum of the probability is above a
  203. * global limit pmin and the difference between local maximum and local minimum is greater than
  204. * minProbabilityDiff).
  205. * param cb automatically generated
  206. * return automatically generated
  207. */
  208. public static ERFilter createERFilterNM1(ERFilter_Callback cb)
  209. {
  210. if (cb != null) cb.ThrowIfDisposed();
  211. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM1_16(cb.getNativeObjAddr())));
  212. }
  213. //
  214. // C++: Ptr_ERFilter cv::text::createERFilterNM2(Ptr_ERFilter_Callback cb, float minProbability = (float)0.3)
  215. //
  216. /**
  217. * Create an Extremal Region Filter for the 2nd stage classifier of N&amp;M algorithm CITE: Neumann12.
  218. *
  219. * loadClassifierNM2, e.g. from file in samples/cpp/trained_classifierNM2.xml
  220. *
  221. * In the second stage, the ERs that passed the first stage are classified into character and
  222. * non-character classes using more informative but also more computationally expensive features. The
  223. * classifier uses all the features calculated in the first stage and the following additional
  224. * features: hole area ratio, convex hull ratio, and number of outer inflexion points.
  225. * param cb automatically generated
  226. * param minProbability automatically generated
  227. * return automatically generated
  228. */
  229. public static ERFilter createERFilterNM2(ERFilter_Callback cb, float minProbability)
  230. {
  231. if (cb != null) cb.ThrowIfDisposed();
  232. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM2_10(cb.getNativeObjAddr(), minProbability)));
  233. }
  234. /**
  235. * Create an Extremal Region Filter for the 2nd stage classifier of N&amp;M algorithm CITE: Neumann12.
  236. *
  237. * loadClassifierNM2, e.g. from file in samples/cpp/trained_classifierNM2.xml
  238. *
  239. * In the second stage, the ERs that passed the first stage are classified into character and
  240. * non-character classes using more informative but also more computationally expensive features. The
  241. * classifier uses all the features calculated in the first stage and the following additional
  242. * features: hole area ratio, convex hull ratio, and number of outer inflexion points.
  243. * param cb automatically generated
  244. * return automatically generated
  245. */
  246. public static ERFilter createERFilterNM2(ERFilter_Callback cb)
  247. {
  248. if (cb != null) cb.ThrowIfDisposed();
  249. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM2_11(cb.getNativeObjAddr())));
  250. }
  251. //
  252. // C++: Ptr_ERFilter cv::text::createERFilterNM1(String filename, int thresholdDelta = 1, float minArea = (float)0.00025, float maxArea = (float)0.13, float minProbability = (float)0.4, bool nonMaxSuppression = true, float minProbabilityDiff = (float)0.1)
  253. //
  254. /**
  255. * Reads an Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm
  256. * from the provided path e.g. /path/to/cpp/trained_classifierNM1.xml
  257. *
  258. * param filename automatically generated
  259. * param thresholdDelta automatically generated
  260. * param minArea automatically generated
  261. * param maxArea automatically generated
  262. * param minProbability automatically generated
  263. * param nonMaxSuppression automatically generated
  264. * param minProbabilityDiff automatically generated
  265. * return automatically generated
  266. */
  267. public static ERFilter createERFilterNM1(string filename, int thresholdDelta, float minArea, float maxArea, float minProbability, bool nonMaxSuppression, float minProbabilityDiff)
  268. {
  269. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM1_17(filename, thresholdDelta, minArea, maxArea, minProbability, nonMaxSuppression, minProbabilityDiff)));
  270. }
  271. /**
  272. * Reads an Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm
  273. * from the provided path e.g. /path/to/cpp/trained_classifierNM1.xml
  274. *
  275. * param filename automatically generated
  276. * param thresholdDelta automatically generated
  277. * param minArea automatically generated
  278. * param maxArea automatically generated
  279. * param minProbability automatically generated
  280. * param nonMaxSuppression automatically generated
  281. * return automatically generated
  282. */
  283. public static ERFilter createERFilterNM1(string filename, int thresholdDelta, float minArea, float maxArea, float minProbability, bool nonMaxSuppression)
  284. {
  285. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM1_18(filename, thresholdDelta, minArea, maxArea, minProbability, nonMaxSuppression)));
  286. }
  287. /**
  288. * Reads an Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm
  289. * from the provided path e.g. /path/to/cpp/trained_classifierNM1.xml
  290. *
  291. * param filename automatically generated
  292. * param thresholdDelta automatically generated
  293. * param minArea automatically generated
  294. * param maxArea automatically generated
  295. * param minProbability automatically generated
  296. * return automatically generated
  297. */
  298. public static ERFilter createERFilterNM1(string filename, int thresholdDelta, float minArea, float maxArea, float minProbability)
  299. {
  300. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM1_19(filename, thresholdDelta, minArea, maxArea, minProbability)));
  301. }
  302. /**
  303. * Reads an Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm
  304. * from the provided path e.g. /path/to/cpp/trained_classifierNM1.xml
  305. *
  306. * param filename automatically generated
  307. * param thresholdDelta automatically generated
  308. * param minArea automatically generated
  309. * param maxArea automatically generated
  310. * return automatically generated
  311. */
  312. public static ERFilter createERFilterNM1(string filename, int thresholdDelta, float minArea, float maxArea)
  313. {
  314. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM1_110(filename, thresholdDelta, minArea, maxArea)));
  315. }
  316. /**
  317. * Reads an Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm
  318. * from the provided path e.g. /path/to/cpp/trained_classifierNM1.xml
  319. *
  320. * param filename automatically generated
  321. * param thresholdDelta automatically generated
  322. * param minArea automatically generated
  323. * return automatically generated
  324. */
  325. public static ERFilter createERFilterNM1(string filename, int thresholdDelta, float minArea)
  326. {
  327. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM1_111(filename, thresholdDelta, minArea)));
  328. }
  329. /**
  330. * Reads an Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm
  331. * from the provided path e.g. /path/to/cpp/trained_classifierNM1.xml
  332. *
  333. * param filename automatically generated
  334. * param thresholdDelta automatically generated
  335. * return automatically generated
  336. */
  337. public static ERFilter createERFilterNM1(string filename, int thresholdDelta)
  338. {
  339. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM1_112(filename, thresholdDelta)));
  340. }
  341. /**
  342. * Reads an Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm
  343. * from the provided path e.g. /path/to/cpp/trained_classifierNM1.xml
  344. *
  345. * param filename automatically generated
  346. * return automatically generated
  347. */
  348. public static ERFilter createERFilterNM1(string filename)
  349. {
  350. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM1_113(filename)));
  351. }
  352. //
  353. // C++: Ptr_ERFilter cv::text::createERFilterNM2(String filename, float minProbability = (float)0.3)
  354. //
  355. /**
  356. * Reads an Extremal Region Filter for the 2nd stage classifier of N&amp;M algorithm
  357. * from the provided path e.g. /path/to/cpp/trained_classifierNM2.xml
  358. *
  359. * param filename automatically generated
  360. * param minProbability automatically generated
  361. * return automatically generated
  362. */
  363. public static ERFilter createERFilterNM2(string filename, float minProbability)
  364. {
  365. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM2_12(filename, minProbability)));
  366. }
  367. /**
  368. * Reads an Extremal Region Filter for the 2nd stage classifier of N&amp;M algorithm
  369. * from the provided path e.g. /path/to/cpp/trained_classifierNM2.xml
  370. *
  371. * param filename automatically generated
  372. * return automatically generated
  373. */
  374. public static ERFilter createERFilterNM2(string filename)
  375. {
  376. return ERFilter.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_createERFilterNM2_13(filename)));
  377. }
  378. //
  379. // C++: Ptr_ERFilter_Callback cv::text::loadClassifierNM1(String filename)
  380. //
  381. /**
  382. * Allow to implicitly load the default classifier when creating an ERFilter object.
  383. *
  384. * param filename The XML or YAML file with the classifier model (e.g. trained_classifierNM1.xml)
  385. *
  386. * returns a pointer to ERFilter::Callback.
  387. * return automatically generated
  388. */
  389. public static ERFilter_Callback loadClassifierNM1(string filename)
  390. {
  391. return ERFilter_Callback.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_loadClassifierNM1_10(filename)));
  392. }
  393. //
  394. // C++: Ptr_ERFilter_Callback cv::text::loadClassifierNM2(String filename)
  395. //
  396. /**
  397. * Allow to implicitly load the default classifier when creating an ERFilter object.
  398. *
  399. * param filename The XML or YAML file with the classifier model (e.g. trained_classifierNM2.xml)
  400. *
  401. * returns a pointer to ERFilter::Callback.
  402. * return automatically generated
  403. */
  404. public static ERFilter_Callback loadClassifierNM2(string filename)
  405. {
  406. return ERFilter_Callback.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_loadClassifierNM2_10(filename)));
  407. }
  408. //
  409. // C++: void cv::text::computeNMChannels(Mat _src, vector_Mat& _channels, int _mode = ERFILTER_NM_RGBLGrad)
  410. //
  411. /**
  412. * Compute the different channels to be processed independently in the N&amp;M algorithm CITE: Neumann12.
  413. *
  414. * param _src Source image. Must be RGB CV_8UC3.
  415. *
  416. * param _channels Output vector&lt;Mat&gt; where computed channels are stored.
  417. *
  418. * param _mode Mode of operation. Currently the only available options are:
  419. * <b>ERFILTER_NM_RGBLGrad</b> (used by default) and <b>ERFILTER_NM_IHSGrad</b>.
  420. *
  421. * In N&amp;M algorithm, the combination of intensity (I), hue (H), saturation (S), and gradient magnitude
  422. * channels (Grad) are used in order to obtain high localization recall. This implementation also
  423. * provides an alternative combination of red (R), green (G), blue (B), lightness (L), and gradient
  424. * magnitude (Grad).
  425. */
  426. public static void computeNMChannels(Mat _src, List<Mat> _channels, int _mode)
  427. {
  428. if (_src != null) _src.ThrowIfDisposed();
  429. Mat _channels_mat = new Mat();
  430. text_Text_computeNMChannels_10(_src.nativeObj, _channels_mat.nativeObj, _mode);
  431. Converters.Mat_to_vector_Mat(_channels_mat, _channels);
  432. _channels_mat.release();
  433. }
  434. /**
  435. * Compute the different channels to be processed independently in the N&amp;M algorithm CITE: Neumann12.
  436. *
  437. * param _src Source image. Must be RGB CV_8UC3.
  438. *
  439. * param _channels Output vector&lt;Mat&gt; where computed channels are stored.
  440. *
  441. * <b>ERFILTER_NM_RGBLGrad</b> (used by default) and <b>ERFILTER_NM_IHSGrad</b>.
  442. *
  443. * In N&amp;M algorithm, the combination of intensity (I), hue (H), saturation (S), and gradient magnitude
  444. * channels (Grad) are used in order to obtain high localization recall. This implementation also
  445. * provides an alternative combination of red (R), green (G), blue (B), lightness (L), and gradient
  446. * magnitude (Grad).
  447. */
  448. public static void computeNMChannels(Mat _src, List<Mat> _channels)
  449. {
  450. if (_src != null) _src.ThrowIfDisposed();
  451. Mat _channels_mat = new Mat();
  452. text_Text_computeNMChannels_11(_src.nativeObj, _channels_mat.nativeObj);
  453. Converters.Mat_to_vector_Mat(_channels_mat, _channels);
  454. _channels_mat.release();
  455. }
  456. //
  457. // C++: void cv::text::erGrouping(Mat image, Mat channel, vector_vector_Point regions, vector_Rect& groups_rects, int method = ERGROUPING_ORIENTATION_HORIZ, String filename = String(), float minProbablity = (float)0.5)
  458. //
  459. /**
  460. * Find groups of Extremal Regions that are organized as text blocks.
  461. *
  462. *
  463. *
  464. * param regions Vector of ER's retrieved from the ERFilter algorithm from each channel.
  465. *
  466. * provided regions.
  467. *
  468. * param groups_rects The output of the algorithm are stored in this parameter as list of rectangles.
  469. *
  470. * param method Grouping method (see text::erGrouping_Modes). Can be one of ERGROUPING_ORIENTATION_HORIZ,
  471. * ERGROUPING_ORIENTATION_ANY.
  472. *
  473. * param filename The XML or YAML file with the classifier model (e.g.
  474. * samples/trained_classifier_erGrouping.xml). Only to use when grouping method is
  475. * ERGROUPING_ORIENTATION_ANY.
  476. *
  477. * param minProbablity The minimum probability for accepting a group. Only to use when grouping
  478. * method is ERGROUPING_ORIENTATION_ANY.
  479. * param image automatically generated
  480. * param channel automatically generated
  481. */
  482. public static void erGrouping(Mat image, Mat channel, List<MatOfPoint> regions, MatOfRect groups_rects, int method, string filename, float minProbablity)
  483. {
  484. if (image != null) image.ThrowIfDisposed();
  485. if (channel != null) channel.ThrowIfDisposed();
  486. if (groups_rects != null) groups_rects.ThrowIfDisposed();
  487. List<Mat> regions_tmplm = new List<Mat>((regions != null) ? regions.Count : 0);
  488. Mat regions_mat = Converters.vector_vector_Point_to_Mat(regions, regions_tmplm);
  489. Mat groups_rects_mat = groups_rects;
  490. text_Text_erGrouping_10(image.nativeObj, channel.nativeObj, regions_mat.nativeObj, groups_rects_mat.nativeObj, method, filename, minProbablity);
  491. }
  492. /**
  493. * Find groups of Extremal Regions that are organized as text blocks.
  494. *
  495. *
  496. *
  497. * param regions Vector of ER's retrieved from the ERFilter algorithm from each channel.
  498. *
  499. * provided regions.
  500. *
  501. * param groups_rects The output of the algorithm are stored in this parameter as list of rectangles.
  502. *
  503. * param method Grouping method (see text::erGrouping_Modes). Can be one of ERGROUPING_ORIENTATION_HORIZ,
  504. * ERGROUPING_ORIENTATION_ANY.
  505. *
  506. * param filename The XML or YAML file with the classifier model (e.g.
  507. * samples/trained_classifier_erGrouping.xml). Only to use when grouping method is
  508. * ERGROUPING_ORIENTATION_ANY.
  509. *
  510. * method is ERGROUPING_ORIENTATION_ANY.
  511. * param image automatically generated
  512. * param channel automatically generated
  513. */
  514. public static void erGrouping(Mat image, Mat channel, List<MatOfPoint> regions, MatOfRect groups_rects, int method, string filename)
  515. {
  516. if (image != null) image.ThrowIfDisposed();
  517. if (channel != null) channel.ThrowIfDisposed();
  518. if (groups_rects != null) groups_rects.ThrowIfDisposed();
  519. List<Mat> regions_tmplm = new List<Mat>((regions != null) ? regions.Count : 0);
  520. Mat regions_mat = Converters.vector_vector_Point_to_Mat(regions, regions_tmplm);
  521. Mat groups_rects_mat = groups_rects;
  522. text_Text_erGrouping_11(image.nativeObj, channel.nativeObj, regions_mat.nativeObj, groups_rects_mat.nativeObj, method, filename);
  523. }
  524. /**
  525. * Find groups of Extremal Regions that are organized as text blocks.
  526. *
  527. *
  528. *
  529. * param regions Vector of ER's retrieved from the ERFilter algorithm from each channel.
  530. *
  531. * provided regions.
  532. *
  533. * param groups_rects The output of the algorithm are stored in this parameter as list of rectangles.
  534. *
  535. * param method Grouping method (see text::erGrouping_Modes). Can be one of ERGROUPING_ORIENTATION_HORIZ,
  536. * ERGROUPING_ORIENTATION_ANY.
  537. *
  538. * samples/trained_classifier_erGrouping.xml). Only to use when grouping method is
  539. * ERGROUPING_ORIENTATION_ANY.
  540. *
  541. * method is ERGROUPING_ORIENTATION_ANY.
  542. * param image automatically generated
  543. * param channel automatically generated
  544. */
  545. public static void erGrouping(Mat image, Mat channel, List<MatOfPoint> regions, MatOfRect groups_rects, int method)
  546. {
  547. if (image != null) image.ThrowIfDisposed();
  548. if (channel != null) channel.ThrowIfDisposed();
  549. if (groups_rects != null) groups_rects.ThrowIfDisposed();
  550. List<Mat> regions_tmplm = new List<Mat>((regions != null) ? regions.Count : 0);
  551. Mat regions_mat = Converters.vector_vector_Point_to_Mat(regions, regions_tmplm);
  552. Mat groups_rects_mat = groups_rects;
  553. text_Text_erGrouping_12(image.nativeObj, channel.nativeObj, regions_mat.nativeObj, groups_rects_mat.nativeObj, method);
  554. }
  555. /**
  556. * Find groups of Extremal Regions that are organized as text blocks.
  557. *
  558. *
  559. *
  560. * param regions Vector of ER's retrieved from the ERFilter algorithm from each channel.
  561. *
  562. * provided regions.
  563. *
  564. * param groups_rects The output of the algorithm are stored in this parameter as list of rectangles.
  565. *
  566. * ERGROUPING_ORIENTATION_ANY.
  567. *
  568. * samples/trained_classifier_erGrouping.xml). Only to use when grouping method is
  569. * ERGROUPING_ORIENTATION_ANY.
  570. *
  571. * method is ERGROUPING_ORIENTATION_ANY.
  572. * param image automatically generated
  573. * param channel automatically generated
  574. */
  575. public static void erGrouping(Mat image, Mat channel, List<MatOfPoint> regions, MatOfRect groups_rects)
  576. {
  577. if (image != null) image.ThrowIfDisposed();
  578. if (channel != null) channel.ThrowIfDisposed();
  579. if (groups_rects != null) groups_rects.ThrowIfDisposed();
  580. List<Mat> regions_tmplm = new List<Mat>((regions != null) ? regions.Count : 0);
  581. Mat regions_mat = Converters.vector_vector_Point_to_Mat(regions, regions_tmplm);
  582. Mat groups_rects_mat = groups_rects;
  583. text_Text_erGrouping_13(image.nativeObj, channel.nativeObj, regions_mat.nativeObj, groups_rects_mat.nativeObj);
  584. }
  585. //
  586. // C++: void cv::text::detectRegions(Mat image, Ptr_ERFilter er_filter1, Ptr_ERFilter er_filter2, vector_vector_Point& regions)
  587. //
  588. /**
  589. * Converts MSER contours (vector&lt;Point&gt;) to ERStat regions.
  590. *
  591. * param image Source image CV_8UC1 from which the MSERs where extracted.
  592. *
  593. *
  594. * param regions Output where the ERStat regions are stored.
  595. *
  596. * It takes as input the contours provided by the OpenCV MSER feature detector and returns as output
  597. * two vectors of ERStats. This is because MSER() output contains both MSER+ and MSER- regions in a
  598. * single vector&lt;Point&gt;, the function separates them in two different vectors (this is as if the
  599. * ERStats where extracted from two different channels).
  600. *
  601. * An example of MSERsToERStats in use can be found in the text detection webcam_demo:
  602. * &lt;https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/webcam_demo.cpp&gt;
  603. * param er_filter1 automatically generated
  604. * param er_filter2 automatically generated
  605. */
  606. public static void detectRegions(Mat image, ERFilter er_filter1, ERFilter er_filter2, List<MatOfPoint> regions)
  607. {
  608. if (image != null) image.ThrowIfDisposed();
  609. if (er_filter1 != null) er_filter1.ThrowIfDisposed();
  610. if (er_filter2 != null) er_filter2.ThrowIfDisposed();
  611. Mat regions_mat = new Mat();
  612. text_Text_detectRegions_10(image.nativeObj, er_filter1.getNativeObjAddr(), er_filter2.getNativeObjAddr(), regions_mat.nativeObj);
  613. Converters.Mat_to_vector_vector_Point(regions_mat, regions);
  614. regions_mat.release();
  615. }
  616. //
  617. // C++: void cv::text::detectRegions(Mat image, Ptr_ERFilter er_filter1, Ptr_ERFilter er_filter2, vector_Rect& groups_rects, int method = ERGROUPING_ORIENTATION_HORIZ, String filename = String(), float minProbability = (float)0.5)
  618. //
  619. /**
  620. * Extracts text regions from image.
  621. *
  622. * param image Source image where text blocks needs to be extracted from. Should be CV_8UC3 (color).
  623. * param er_filter1 Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm CITE: Neumann12
  624. * param er_filter2 Extremal Region Filter for the 2nd stage classifier of N&amp;M algorithm CITE: Neumann12
  625. * param groups_rects Output list of rectangle blocks with text
  626. * param method Grouping method (see text::erGrouping_Modes). Can be one of ERGROUPING_ORIENTATION_HORIZ, ERGROUPING_ORIENTATION_ANY.
  627. * param filename The XML or YAML file with the classifier model (e.g. samples/trained_classifier_erGrouping.xml). Only to use when grouping method is ERGROUPING_ORIENTATION_ANY.
  628. * param minProbability The minimum probability for accepting a group. Only to use when grouping method is ERGROUPING_ORIENTATION_ANY.
  629. */
  630. public static void detectRegions(Mat image, ERFilter er_filter1, ERFilter er_filter2, MatOfRect groups_rects, int method, string filename, float minProbability)
  631. {
  632. if (image != null) image.ThrowIfDisposed();
  633. if (er_filter1 != null) er_filter1.ThrowIfDisposed();
  634. if (er_filter2 != null) er_filter2.ThrowIfDisposed();
  635. if (groups_rects != null) groups_rects.ThrowIfDisposed();
  636. Mat groups_rects_mat = groups_rects;
  637. text_Text_detectRegions_11(image.nativeObj, er_filter1.getNativeObjAddr(), er_filter2.getNativeObjAddr(), groups_rects_mat.nativeObj, method, filename, minProbability);
  638. }
  639. /**
  640. * Extracts text regions from image.
  641. *
  642. * param image Source image where text blocks needs to be extracted from. Should be CV_8UC3 (color).
  643. * param er_filter1 Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm CITE: Neumann12
  644. * param er_filter2 Extremal Region Filter for the 2nd stage classifier of N&amp;M algorithm CITE: Neumann12
  645. * param groups_rects Output list of rectangle blocks with text
  646. * param method Grouping method (see text::erGrouping_Modes). Can be one of ERGROUPING_ORIENTATION_HORIZ, ERGROUPING_ORIENTATION_ANY.
  647. * param filename The XML or YAML file with the classifier model (e.g. samples/trained_classifier_erGrouping.xml). Only to use when grouping method is ERGROUPING_ORIENTATION_ANY.
  648. */
  649. public static void detectRegions(Mat image, ERFilter er_filter1, ERFilter er_filter2, MatOfRect groups_rects, int method, string filename)
  650. {
  651. if (image != null) image.ThrowIfDisposed();
  652. if (er_filter1 != null) er_filter1.ThrowIfDisposed();
  653. if (er_filter2 != null) er_filter2.ThrowIfDisposed();
  654. if (groups_rects != null) groups_rects.ThrowIfDisposed();
  655. Mat groups_rects_mat = groups_rects;
  656. text_Text_detectRegions_12(image.nativeObj, er_filter1.getNativeObjAddr(), er_filter2.getNativeObjAddr(), groups_rects_mat.nativeObj, method, filename);
  657. }
  658. /**
  659. * Extracts text regions from image.
  660. *
  661. * param image Source image where text blocks needs to be extracted from. Should be CV_8UC3 (color).
  662. * param er_filter1 Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm CITE: Neumann12
  663. * param er_filter2 Extremal Region Filter for the 2nd stage classifier of N&amp;M algorithm CITE: Neumann12
  664. * param groups_rects Output list of rectangle blocks with text
  665. * param method Grouping method (see text::erGrouping_Modes). Can be one of ERGROUPING_ORIENTATION_HORIZ, ERGROUPING_ORIENTATION_ANY.
  666. */
  667. public static void detectRegions(Mat image, ERFilter er_filter1, ERFilter er_filter2, MatOfRect groups_rects, int method)
  668. {
  669. if (image != null) image.ThrowIfDisposed();
  670. if (er_filter1 != null) er_filter1.ThrowIfDisposed();
  671. if (er_filter2 != null) er_filter2.ThrowIfDisposed();
  672. if (groups_rects != null) groups_rects.ThrowIfDisposed();
  673. Mat groups_rects_mat = groups_rects;
  674. text_Text_detectRegions_13(image.nativeObj, er_filter1.getNativeObjAddr(), er_filter2.getNativeObjAddr(), groups_rects_mat.nativeObj, method);
  675. }
  676. /**
  677. * Extracts text regions from image.
  678. *
  679. * param image Source image where text blocks needs to be extracted from. Should be CV_8UC3 (color).
  680. * param er_filter1 Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm CITE: Neumann12
  681. * param er_filter2 Extremal Region Filter for the 2nd stage classifier of N&amp;M algorithm CITE: Neumann12
  682. * param groups_rects Output list of rectangle blocks with text
  683. */
  684. public static void detectRegions(Mat image, ERFilter er_filter1, ERFilter er_filter2, MatOfRect groups_rects)
  685. {
  686. if (image != null) image.ThrowIfDisposed();
  687. if (er_filter1 != null) er_filter1.ThrowIfDisposed();
  688. if (er_filter2 != null) er_filter2.ThrowIfDisposed();
  689. if (groups_rects != null) groups_rects.ThrowIfDisposed();
  690. Mat groups_rects_mat = groups_rects;
  691. text_Text_detectRegions_14(image.nativeObj, er_filter1.getNativeObjAddr(), er_filter2.getNativeObjAddr(), groups_rects_mat.nativeObj);
  692. }
  693. //
  694. // C++: Ptr_OCRHMMDecoder_ClassifierCallback cv::text::loadOCRHMMClassifierNM(String filename)
  695. //
  696. /**
  697. * Allow to implicitly load the default character classifier when creating an OCRHMMDecoder object.
  698. *
  699. * param filename The XML or YAML file with the classifier model (e.g. OCRHMM_knn_model_data.xml)
  700. *
  701. * The KNN default classifier is based in the scene text recognition method proposed by Lukás Neumann &amp;
  702. * Jiri Matas in [Neumann11b]. Basically, the region (contour) in the input image is normalized to a
  703. * fixed size, while retaining the centroid and aspect ratio, in order to extract a feature vector
  704. * based on gradient orientations along the chain-code of its perimeter. Then, the region is classified
  705. * using a KNN model trained with synthetic data of rendered characters with different standard font
  706. * types.
  707. *
  708. * deprecated loadOCRHMMClassifier instead
  709. * return automatically generated
  710. */
  711. [Obsolete("This method is deprecated.")]
  712. public static OCRHMMDecoder_ClassifierCallback loadOCRHMMClassifierNM(string filename)
  713. {
  714. return OCRHMMDecoder_ClassifierCallback.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_loadOCRHMMClassifierNM_10(filename)));
  715. }
  716. //
  717. // C++: Ptr_OCRHMMDecoder_ClassifierCallback cv::text::loadOCRHMMClassifierCNN(String filename)
  718. //
  719. /**
  720. * Allow to implicitly load the default character classifier when creating an OCRHMMDecoder object.
  721. *
  722. * param filename The XML or YAML file with the classifier model (e.g. OCRBeamSearch_CNN_model_data.xml.gz)
  723. *
  724. * The CNN default classifier is based in the scene text recognition method proposed by Adam Coates &amp;
  725. * Andrew NG in [Coates11a]. The character classifier consists in a Single Layer Convolutional Neural Network and
  726. * a linear classifier. It is applied to the input image in a sliding window fashion, providing a set of recognitions
  727. * at each window location.
  728. *
  729. * deprecated use loadOCRHMMClassifier instead
  730. * return automatically generated
  731. */
  732. [Obsolete("This method is deprecated.")]
  733. public static OCRHMMDecoder_ClassifierCallback loadOCRHMMClassifierCNN(string filename)
  734. {
  735. return OCRHMMDecoder_ClassifierCallback.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_loadOCRHMMClassifierCNN_10(filename)));
  736. }
  737. //
  738. // C++: Ptr_OCRHMMDecoder_ClassifierCallback cv::text::loadOCRHMMClassifier(String filename, int classifier)
  739. //
  740. /**
  741. * Allow to implicitly load the default character classifier when creating an OCRHMMDecoder object.
  742. *
  743. * param filename The XML or YAML file with the classifier model (e.g. OCRBeamSearch_CNN_model_data.xml.gz)
  744. *
  745. * param classifier Can be one of classifier_type enum values.
  746. * return automatically generated
  747. */
  748. public static OCRHMMDecoder_ClassifierCallback loadOCRHMMClassifier(string filename, int classifier)
  749. {
  750. return OCRHMMDecoder_ClassifierCallback.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_loadOCRHMMClassifier_10(filename, classifier)));
  751. }
  752. //
  753. // C++: Mat cv::text::createOCRHMMTransitionsTable(String vocabulary, vector_String lexicon)
  754. //
  755. /**
  756. * Utility function to create a tailored language model transitions table from a given list of words (lexicon).
  757. *
  758. * param vocabulary The language vocabulary (chars when ASCII English text).
  759. *
  760. * param lexicon The list of words that are expected to be found in a particular image.
  761. *
  762. *
  763. * The function calculate frequency statistics of character pairs from the given lexicon and fills the output transition_probabilities_table with them. The transition_probabilities_table can be used as input in the OCRHMMDecoder::create() and OCRBeamSearchDecoder::create() methods.
  764. * <b>Note:</b>
  765. * - (C++) An alternative would be to load the default generic language transition table provided in the text module samples folder (created from ispell 42869 english words list) :
  766. * &lt;https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/OCRHMM_transitions_table.xml&gt;
  767. *
  768. * return automatically generated
  769. */
  770. public static Mat createOCRHMMTransitionsTable(string vocabulary, List<string> lexicon)
  771. {
  772. Mat lexicon_mat = Converters.vector_String_to_Mat(lexicon);
  773. return new Mat(DisposableObject.ThrowIfNullIntPtr(text_Text_createOCRHMMTransitionsTable_10(vocabulary, lexicon_mat.nativeObj)));
  774. }
  775. //
  776. // C++: Ptr_OCRBeamSearchDecoder_ClassifierCallback cv::text::loadOCRBeamSearchClassifierCNN(String filename)
  777. //
  778. /**
  779. * Allow to implicitly load the default character classifier when creating an OCRBeamSearchDecoder object.
  780. *
  781. * param filename The XML or YAML file with the classifier model (e.g. OCRBeamSearch_CNN_model_data.xml.gz)
  782. *
  783. * The CNN default classifier is based in the scene text recognition method proposed by Adam Coates &amp;
  784. * Andrew NG in [Coates11a]. The character classifier consists in a Single Layer Convolutional Neural Network and
  785. * a linear classifier. It is applied to the input image in a sliding window fashion, providing a set of recognitions
  786. * at each window location.
  787. * return automatically generated
  788. */
  789. public static OCRBeamSearchDecoder_ClassifierCallback loadOCRBeamSearchClassifierCNN(string filename)
  790. {
  791. return OCRBeamSearchDecoder_ClassifierCallback.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(text_Text_loadOCRBeamSearchClassifierCNN_10(filename)));
  792. }
  793. //
  794. // C++: void cv::text::detectTextSWT(Mat input, vector_Rect& result, bool dark_on_light, Mat& draw = Mat(), Mat& chainBBs = Mat())
  795. //
  796. /**
  797. * Applies the Stroke Width Transform operator followed by filtering of connected components of similar Stroke Widths to return letter candidates. It also chain them by proximity and size, saving the result in chainBBs.
  798. * param input the input image with 3 channels.
  799. * param result a vector of resulting bounding boxes where probability of finding text is high
  800. * param dark_on_light a boolean value signifying whether the text is darker or lighter than the background, it is observed to reverse the gradient obtained from Scharr operator, and significantly affect the result.
  801. * param draw an optional Mat of type CV_8UC3 which visualises the detected letters using bounding boxes.
  802. * param chainBBs an optional parameter which chains the letter candidates according to heuristics in the paper and returns all possible regions where text is likely to occur.
  803. */
  804. public static void detectTextSWT(Mat input, MatOfRect result, bool dark_on_light, Mat draw, Mat chainBBs)
  805. {
  806. if (input != null) input.ThrowIfDisposed();
  807. if (result != null) result.ThrowIfDisposed();
  808. if (draw != null) draw.ThrowIfDisposed();
  809. if (chainBBs != null) chainBBs.ThrowIfDisposed();
  810. Mat result_mat = result;
  811. text_Text_detectTextSWT_10(input.nativeObj, result_mat.nativeObj, dark_on_light, draw.nativeObj, chainBBs.nativeObj);
  812. }
  813. /**
  814. * Applies the Stroke Width Transform operator followed by filtering of connected components of similar Stroke Widths to return letter candidates. It also chain them by proximity and size, saving the result in chainBBs.
  815. * param input the input image with 3 channels.
  816. * param result a vector of resulting bounding boxes where probability of finding text is high
  817. * param dark_on_light a boolean value signifying whether the text is darker or lighter than the background, it is observed to reverse the gradient obtained from Scharr operator, and significantly affect the result.
  818. * param draw an optional Mat of type CV_8UC3 which visualises the detected letters using bounding boxes.
  819. */
  820. public static void detectTextSWT(Mat input, MatOfRect result, bool dark_on_light, Mat draw)
  821. {
  822. if (input != null) input.ThrowIfDisposed();
  823. if (result != null) result.ThrowIfDisposed();
  824. if (draw != null) draw.ThrowIfDisposed();
  825. Mat result_mat = result;
  826. text_Text_detectTextSWT_11(input.nativeObj, result_mat.nativeObj, dark_on_light, draw.nativeObj);
  827. }
  828. /**
  829. * Applies the Stroke Width Transform operator followed by filtering of connected components of similar Stroke Widths to return letter candidates. It also chain them by proximity and size, saving the result in chainBBs.
  830. * param input the input image with 3 channels.
  831. * param result a vector of resulting bounding boxes where probability of finding text is high
  832. * param dark_on_light a boolean value signifying whether the text is darker or lighter than the background, it is observed to reverse the gradient obtained from Scharr operator, and significantly affect the result.
  833. */
  834. public static void detectTextSWT(Mat input, MatOfRect result, bool dark_on_light)
  835. {
  836. if (input != null) input.ThrowIfDisposed();
  837. if (result != null) result.ThrowIfDisposed();
  838. Mat result_mat = result;
  839. text_Text_detectTextSWT_12(input.nativeObj, result_mat.nativeObj, dark_on_light);
  840. }
  841. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  842. const string LIBNAME = "__Internal";
  843. #else
  844. const string LIBNAME = "opencvforunity";
  845. #endif
  846. // C++: Ptr_ERFilter cv::text::createERFilterNM1(Ptr_ERFilter_Callback cb, int thresholdDelta = 1, float minArea = (float)0.00025, float maxArea = (float)0.13, float minProbability = (float)0.4, bool nonMaxSuppression = true, float minProbabilityDiff = (float)0.1)
  847. [DllImport(LIBNAME)]
  848. private static extern IntPtr text_Text_createERFilterNM1_10(IntPtr cb_nativeObj, int thresholdDelta, float minArea, float maxArea, float minProbability, [MarshalAs(UnmanagedType.U1)] bool nonMaxSuppression, float minProbabilityDiff);
  849. [DllImport(LIBNAME)]
  850. private static extern IntPtr text_Text_createERFilterNM1_11(IntPtr cb_nativeObj, int thresholdDelta, float minArea, float maxArea, float minProbability, [MarshalAs(UnmanagedType.U1)] bool nonMaxSuppression);
  851. [DllImport(LIBNAME)]
  852. private static extern IntPtr text_Text_createERFilterNM1_12(IntPtr cb_nativeObj, int thresholdDelta, float minArea, float maxArea, float minProbability);
  853. [DllImport(LIBNAME)]
  854. private static extern IntPtr text_Text_createERFilterNM1_13(IntPtr cb_nativeObj, int thresholdDelta, float minArea, float maxArea);
  855. [DllImport(LIBNAME)]
  856. private static extern IntPtr text_Text_createERFilterNM1_14(IntPtr cb_nativeObj, int thresholdDelta, float minArea);
  857. [DllImport(LIBNAME)]
  858. private static extern IntPtr text_Text_createERFilterNM1_15(IntPtr cb_nativeObj, int thresholdDelta);
  859. [DllImport(LIBNAME)]
  860. private static extern IntPtr text_Text_createERFilterNM1_16(IntPtr cb_nativeObj);
  861. // C++: Ptr_ERFilter cv::text::createERFilterNM2(Ptr_ERFilter_Callback cb, float minProbability = (float)0.3)
  862. [DllImport(LIBNAME)]
  863. private static extern IntPtr text_Text_createERFilterNM2_10(IntPtr cb_nativeObj, float minProbability);
  864. [DllImport(LIBNAME)]
  865. private static extern IntPtr text_Text_createERFilterNM2_11(IntPtr cb_nativeObj);
  866. // C++: Ptr_ERFilter cv::text::createERFilterNM1(String filename, int thresholdDelta = 1, float minArea = (float)0.00025, float maxArea = (float)0.13, float minProbability = (float)0.4, bool nonMaxSuppression = true, float minProbabilityDiff = (float)0.1)
  867. [DllImport(LIBNAME)]
  868. private static extern IntPtr text_Text_createERFilterNM1_17(string filename, int thresholdDelta, float minArea, float maxArea, float minProbability, [MarshalAs(UnmanagedType.U1)] bool nonMaxSuppression, float minProbabilityDiff);
  869. [DllImport(LIBNAME)]
  870. private static extern IntPtr text_Text_createERFilterNM1_18(string filename, int thresholdDelta, float minArea, float maxArea, float minProbability, [MarshalAs(UnmanagedType.U1)] bool nonMaxSuppression);
  871. [DllImport(LIBNAME)]
  872. private static extern IntPtr text_Text_createERFilterNM1_19(string filename, int thresholdDelta, float minArea, float maxArea, float minProbability);
  873. [DllImport(LIBNAME)]
  874. private static extern IntPtr text_Text_createERFilterNM1_110(string filename, int thresholdDelta, float minArea, float maxArea);
  875. [DllImport(LIBNAME)]
  876. private static extern IntPtr text_Text_createERFilterNM1_111(string filename, int thresholdDelta, float minArea);
  877. [DllImport(LIBNAME)]
  878. private static extern IntPtr text_Text_createERFilterNM1_112(string filename, int thresholdDelta);
  879. [DllImport(LIBNAME)]
  880. private static extern IntPtr text_Text_createERFilterNM1_113(string filename);
  881. // C++: Ptr_ERFilter cv::text::createERFilterNM2(String filename, float minProbability = (float)0.3)
  882. [DllImport(LIBNAME)]
  883. private static extern IntPtr text_Text_createERFilterNM2_12(string filename, float minProbability);
  884. [DllImport(LIBNAME)]
  885. private static extern IntPtr text_Text_createERFilterNM2_13(string filename);
  886. // C++: Ptr_ERFilter_Callback cv::text::loadClassifierNM1(String filename)
  887. [DllImport(LIBNAME)]
  888. private static extern IntPtr text_Text_loadClassifierNM1_10(string filename);
  889. // C++: Ptr_ERFilter_Callback cv::text::loadClassifierNM2(String filename)
  890. [DllImport(LIBNAME)]
  891. private static extern IntPtr text_Text_loadClassifierNM2_10(string filename);
  892. // C++: void cv::text::computeNMChannels(Mat _src, vector_Mat& _channels, int _mode = ERFILTER_NM_RGBLGrad)
  893. [DllImport(LIBNAME)]
  894. private static extern void text_Text_computeNMChannels_10(IntPtr _src_nativeObj, IntPtr _channels_mat_nativeObj, int _mode);
  895. [DllImport(LIBNAME)]
  896. private static extern void text_Text_computeNMChannels_11(IntPtr _src_nativeObj, IntPtr _channels_mat_nativeObj);
  897. // C++: void cv::text::erGrouping(Mat image, Mat channel, vector_vector_Point regions, vector_Rect& groups_rects, int method = ERGROUPING_ORIENTATION_HORIZ, String filename = String(), float minProbablity = (float)0.5)
  898. [DllImport(LIBNAME)]
  899. private static extern void text_Text_erGrouping_10(IntPtr image_nativeObj, IntPtr channel_nativeObj, IntPtr regions_mat_nativeObj, IntPtr groups_rects_mat_nativeObj, int method, string filename, float minProbablity);
  900. [DllImport(LIBNAME)]
  901. private static extern void text_Text_erGrouping_11(IntPtr image_nativeObj, IntPtr channel_nativeObj, IntPtr regions_mat_nativeObj, IntPtr groups_rects_mat_nativeObj, int method, string filename);
  902. [DllImport(LIBNAME)]
  903. private static extern void text_Text_erGrouping_12(IntPtr image_nativeObj, IntPtr channel_nativeObj, IntPtr regions_mat_nativeObj, IntPtr groups_rects_mat_nativeObj, int method);
  904. [DllImport(LIBNAME)]
  905. private static extern void text_Text_erGrouping_13(IntPtr image_nativeObj, IntPtr channel_nativeObj, IntPtr regions_mat_nativeObj, IntPtr groups_rects_mat_nativeObj);
  906. // C++: void cv::text::detectRegions(Mat image, Ptr_ERFilter er_filter1, Ptr_ERFilter er_filter2, vector_vector_Point& regions)
  907. [DllImport(LIBNAME)]
  908. private static extern void text_Text_detectRegions_10(IntPtr image_nativeObj, IntPtr er_filter1_nativeObj, IntPtr er_filter2_nativeObj, IntPtr regions_mat_nativeObj);
  909. // C++: void cv::text::detectRegions(Mat image, Ptr_ERFilter er_filter1, Ptr_ERFilter er_filter2, vector_Rect& groups_rects, int method = ERGROUPING_ORIENTATION_HORIZ, String filename = String(), float minProbability = (float)0.5)
  910. [DllImport(LIBNAME)]
  911. private static extern void text_Text_detectRegions_11(IntPtr image_nativeObj, IntPtr er_filter1_nativeObj, IntPtr er_filter2_nativeObj, IntPtr groups_rects_mat_nativeObj, int method, string filename, float minProbability);
  912. [DllImport(LIBNAME)]
  913. private static extern void text_Text_detectRegions_12(IntPtr image_nativeObj, IntPtr er_filter1_nativeObj, IntPtr er_filter2_nativeObj, IntPtr groups_rects_mat_nativeObj, int method, string filename);
  914. [DllImport(LIBNAME)]
  915. private static extern void text_Text_detectRegions_13(IntPtr image_nativeObj, IntPtr er_filter1_nativeObj, IntPtr er_filter2_nativeObj, IntPtr groups_rects_mat_nativeObj, int method);
  916. [DllImport(LIBNAME)]
  917. private static extern void text_Text_detectRegions_14(IntPtr image_nativeObj, IntPtr er_filter1_nativeObj, IntPtr er_filter2_nativeObj, IntPtr groups_rects_mat_nativeObj);
  918. // C++: Ptr_OCRHMMDecoder_ClassifierCallback cv::text::loadOCRHMMClassifierNM(String filename)
  919. [DllImport(LIBNAME)]
  920. private static extern IntPtr text_Text_loadOCRHMMClassifierNM_10(string filename);
  921. // C++: Ptr_OCRHMMDecoder_ClassifierCallback cv::text::loadOCRHMMClassifierCNN(String filename)
  922. [DllImport(LIBNAME)]
  923. private static extern IntPtr text_Text_loadOCRHMMClassifierCNN_10(string filename);
  924. // C++: Ptr_OCRHMMDecoder_ClassifierCallback cv::text::loadOCRHMMClassifier(String filename, int classifier)
  925. [DllImport(LIBNAME)]
  926. private static extern IntPtr text_Text_loadOCRHMMClassifier_10(string filename, int classifier);
  927. // C++: Mat cv::text::createOCRHMMTransitionsTable(String vocabulary, vector_String lexicon)
  928. [DllImport(LIBNAME)]
  929. private static extern IntPtr text_Text_createOCRHMMTransitionsTable_10(string vocabulary, IntPtr lexicon_mat_nativeObj);
  930. // C++: Ptr_OCRBeamSearchDecoder_ClassifierCallback cv::text::loadOCRBeamSearchClassifierCNN(String filename)
  931. [DllImport(LIBNAME)]
  932. private static extern IntPtr text_Text_loadOCRBeamSearchClassifierCNN_10(string filename);
  933. // C++: void cv::text::detectTextSWT(Mat input, vector_Rect& result, bool dark_on_light, Mat& draw = Mat(), Mat& chainBBs = Mat())
  934. [DllImport(LIBNAME)]
  935. private static extern void text_Text_detectTextSWT_10(IntPtr input_nativeObj, IntPtr result_mat_nativeObj, [MarshalAs(UnmanagedType.U1)] bool dark_on_light, IntPtr draw_nativeObj, IntPtr chainBBs_nativeObj);
  936. [DllImport(LIBNAME)]
  937. private static extern void text_Text_detectTextSWT_11(IntPtr input_nativeObj, IntPtr result_mat_nativeObj, [MarshalAs(UnmanagedType.U1)] bool dark_on_light, IntPtr draw_nativeObj);
  938. [DllImport(LIBNAME)]
  939. private static extern void text_Text_detectTextSWT_12(IntPtr input_nativeObj, IntPtr result_mat_nativeObj, [MarshalAs(UnmanagedType.U1)] bool dark_on_light);
  940. }
  941. }
  942. #endif