# Problems with Dnn TextDetectors (TextDetectionModel\_DB & TextDetectionModel\_EAST) on Android

**URL:** <https://forum.opencv.org/t/problems-with-dnn-textdetectors-textdetectionmodel-db-textdetectionmodel-east-on-android/11189>\
**Category:** Android/Java\
**Tags:** dnn, android, text\
**Created:** [December 3, 2022, 5:35pm UTC](https://forum.opencv.org/t/problems-with-dnn-textdetectors-textdetectionmodel-db-textdetectionmodel-east-on-android/11189 "2022-12-03T17:35:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kinetix](https://avatars.discourse-cdn.com/v4/letter/k/8edcca/32.png) [@kinetix](https://forum.opencv.org/u/kinetix)\
**Post date:** [December 3, 2022, 5:35pm UTC](https://forum.opencv.org/t/problems-with-dnn-textdetectors-textdetectionmodel-db-textdetectionmodel-east-on-android/11189/1 "2022-12-03T17:35:40Z")

</div>

I’m having several problems with text detection in android/java. I have everything written initially in C++ for testing and debugging, so far so good. but when running on android, it fails me in various ways. I will make a post for each one separately.  
I’m using Opencv 4.5.1 for Android, and ARM v8, full built by my self from source, including extras and non-free. The app is the same. Running on Android 6.0.1.

* * *

using the DB\_TD500\_resnet18.onnx model

* * *

initialization

```
  int height = 320; 
  int width = 320;
  detector = new TextDetectionModel_DB(modelFilename); 
  detector.setBinaryThreshold(0.3);
  detector.setPolygonThreshold(0.5);
  detector.setUnclipRatio(3.0);
  detector.setMaxCandidates(200);
  detector.setInputParams(1.0 / 255.0, new Size(width, height), new Scalar(122.67891434, 116.66876762, 104.00698793));

```

then when detecting

```
 Mat imageDetect = new Mat( height, width, CvType.CV_8UC3 );
 Mat imageT = new Mat();
 Imgproc.resize(imageIn, imageT, new Size(width, height)); //just in case
 Imgproc.cvtColor(imageT, imageDetect, Imgproc.COLOR_BGRA2BGR); //4 to 3 channels as the model needs;
 List<MatOfPoint> detResults = new ArrayList<>();
 MatOfFloat detConfid = new MatOfFloat();
 detector.detect(imageDetect, detResults, detConfid); //<<<<<ERROR!

```

the error says:

```
 E/cv::error(): OpenCV(4.5.1) Error: Incorrect size of input array (Input size not specified) in processFrame, file C:/LIBs/opencv4.5.1/sources/modules/dnn/src/model.cpp, line 96
  E/org.opencv.dnn: dnn::detect_10() caught cv::Exception: OpenCV(4.5.1) C:/LIBs/opencv4.5.1/sources/modules/dnn/src/model.cpp:96: error: (-201:Incorrect size of input array) Input size not specified in function 'processFrame'
CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.5.1) C:/LIBs/opencv4.5.1/sources/modules/dnn/src/model.cpp:96: error: (-201:Incorrect size of input array) Input size not specified in function 'processFrame'
              ]
                  at org.opencv.dnn.TextDetectionModel.detect_0(Native Method)
                  at org.opencv.dnn.TextDetectionModel.detect(TextDetectionModel.java:52)
                  at abc.OCR_AI.OCR_AI.Recognice_TextInTheWild(OCR_AI.java:145)
                  at abc.MainActivity$4.run(MainActivity.java:1081)
                  at java.lang.Thread.run(Thread.java:833)         

```

the line on OpenCV source code reads:  
if (size.empty()) CV\_Error(Error::StsBadSize, “Input size not specified”);

but, **I did set the size before**!

with TextDetectionModel\_EAST is the same (also manage to find another one when I set the initial settings)

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [December 3, 2022, 5:38pm UTC](https://forum.opencv.org/t/problems-with-dnn-textdetectors-textdetectionmodel-db-textdetectionmodel-east-on-android/11189/2 "2022-12-03T17:38:16Z")

</div>

> [@kinetix](#):
>
> `imageDtect`

[MRE](https://stackoverflow.com/help/minimal-reproducible-example) please. you gave no information on that variable.

---

<div class="post-metadata">

**Author:** ![kinetix](https://avatars.discourse-cdn.com/v4/letter/k/8edcca/32.png) [@kinetix](https://forum.opencv.org/u/kinetix)\
**Post date:** [December 3, 2022, 6:24pm UTC](https://forum.opencv.org/t/problems-with-dnn-textdetectors-textdetectionmodel-db-textdetectionmodel-east-on-android/11189/4 "2022-12-03T18:24:53Z")

</div>

I just corrected the post.  
is just an image

---

<div class="post-metadata">

**Author:** ![matti.vuori](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@matti.vuori](https://forum.opencv.org/u/matti.vuori)\
**Post date:** [December 3, 2022, 6:41pm UTC](https://forum.opencv.org/t/problems-with-dnn-textdetectors-textdetectionmodel-db-textdetectionmodel-east-on-android/11189/5 "2022-12-03T18:41:28Z")

</div>

All depends on ImageIn. Perhaps reading it fails.You don’t show how you do it and check that it goes ok.

Meta advice: You should check every line for success and every Mat for validity.

---

<div class="post-metadata">

**Author:** ![kinetix](https://avatars.discourse-cdn.com/v4/letter/k/8edcca/32.png) [@kinetix](https://forum.opencv.org/u/kinetix)\
**Post date:** [December 3, 2022, 6:42pm UTC](https://forum.opencv.org/t/problems-with-dnn-textdetectors-textdetectionmodel-db-textdetectionmodel-east-on-android/11189/6 "2022-12-03T18:42:32Z")

</div>

I did it.  
But I’ll check again.  
…  
…  
the image is right  
a shame the detector don’t have something like a “getSize”, so you can check it is well initialized

---

<div class="post-metadata">

**Author:** ![kinetix](https://avatars.discourse-cdn.com/v4/letter/k/8edcca/32.png) [@kinetix](https://forum.opencv.org/u/kinetix)\
**Post date:** [December 7, 2022, 11:14pm UTC](https://forum.opencv.org/t/problems-with-dnn-textdetectors-textdetectionmodel-db-textdetectionmodel-east-on-android/11189/7 "2022-12-07T23:14:51Z")

</div>

TextDetectionModel\_DB, TextDetectionModel\_EAST and TextRecognitionModel all three give me the same error.  
Can you give me a real working example to test?  
I am now using the models directly, and partially replicating the post-processing helper functions in Java to continue the work. but doing this is somewhat cumbersome when everything is already done in the library.
