I'am writing Tess-two based OCR system for android
and stumbled upon strange obstacle. I actually use TextureView
connected with deprecated Camera
and when I try to execute this code on my Huawei P8:
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
Log.d("frame", "update frame");
if(btmQueue.size()<10)
btmQueue.add(mTextureView.getBitmap());
System.out.println(mOCRWorker.isAlive());
if(mOCRWorker.isAlive()==false)
{
mOCRWorker.start();
}
}
Thread mOCRWorker = new Thread(new Runnable() {
@Override
public void run() {
Log.d("Ocr:", "Running thread!");
if(apiInit==true) {
if (btmQueue.size() > 0) {
Bitmap bmp = btmQueue.pollFirst();
baseAPI.setImage(bmp);
String recognizedText = baseAPI.getUTF8Text();
Log.d("Recognized: ", recognizedText);
}
}
Log.d("Ocr:", "Thread finished!");
}
});
I get this error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.user.myApp, PID: 18386
java.lang.IllegalThreadStateException: Thread already started
at java.lang.Thread.checkNotStarted(Thread.java:864)
at java.lang.Thread.start(Thread.java:1074) [...]
I thought that that if isAlive()
gives me false then my Thread is actually dead. Do you have any clue what is going on?
Okey, I figured it out: Method start() can't be invoked more than once for any Thread - even and especially when Thread were executed. I put while(ocrShouldWork) loop inside my Thread to keep it working till I turn it off.