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)