1. add ocr license

2. add hyper-lpr function
3. add text filter
4. add commits
This commit is contained in:
UnknownObject
2022-11-13 23:41:47 +08:00
parent 254ef1e18b
commit f9bb7d9487
116 changed files with 23682 additions and 354 deletions
@@ -48,6 +48,7 @@ import com.uns.maincar.cpp_interface.TrafficLight;
import com.uns.maincar.cpp_interface.TrafficSign;
import com.uns.maincar.tools.ImageReleaser;
import com.uns.maincar.tools.OCRDataReleaser;
import com.uns.maincar.tools.TextFilter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
@@ -106,105 +107,144 @@ public class MainActivity extends AppCompatActivity
"0xE0", "0xE1", "0xE2", "0xE3", "0xE4", "0xE5", "0xE6", "0xE7", "0xE8", "0xE9", "0xEA", "0xEB", "0xEC", "0xED", "0xEE", "0xEF",
"0xF0", "0xF1", "0xF2", "0xF3", "0xF4", "0xF5", "0xF6", "0xF7", "0xF8", "0xF9", "0xFA", "0xFB", "0xFC", "0xFD", "0xFE", "0xFF"};
static
{
System.loadLibrary("opencv_support");
}
//原生函数导入,用于长按保存的功能
private static native boolean SaveImage(Bitmap img, String time);
@SuppressLint("HandlerLeak")
public MainActivity()
{
//接收内部消息的处理器,用于处理内部消息
recvHandler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
super.handleMessage(msg);
//处理接收到的图片
//内部消息:收到图片;执行操作:更新GUI上的图片
if (msg.what == Flags.RECEIVED_IMAGE)
pic_received.setImageBitmap(currImage);
//处理接收到的指令
//内部消息:收到主车数据;执行操作:解析指令并执行
if (msg.what == Flags.RECEIVED_CAR_DATA)
{
byte[] recv = (byte[]) msg.obj;
if (recv != null)
{
//打印接收到的指令
ToastLog("RECV: [" + ByteArray2String(recv) + "]", true, false);
//解析指令
CommandDecoder decoder = new CommandDecoder(recv);
if (decoder.CommandReady())
{
ToastLog("Command Decode Ready.", false, false);
Thread th_run_command = new Thread(() -> {
Thread th_run_command = new Thread(() ->
{
switch (decoder.GetMainCommand())
{
//收到全自动指令,返回程序自检状态
case Commands.RECEIVE_FULL_AUTO:
dtc_client.Send(SystemStatusCommand());
break;
//收到QR指令,开始识别二维码,回传识别成功的数据
case Commands.RECEIVE_QR:
byte[] cmd = RecognizeQrCode();
CommandEncoder encoder = new CommandEncoder();
dtc_client.Send(encoder.GenerateCommand(Commands.QR_SUCCESS_1, cmd[0], cmd[1], cmd[2]));
Sleep(500);
dtc_client.Send(encoder.GenerateCommand(Commands.QR_SUCCESS_2, cmd[3], cmd[4], cmd[5]));
if (cmd[2] == Commands.QR_FAILED)
dtc_client.Send(cmd);
else
{
CommandEncoder encoder = new CommandEncoder();
dtc_client.Send(encoder.GenerateCommand(Commands.QR_SUCCESS_1, cmd[0], cmd[1], cmd[2]));
Sleep(500);
dtc_client.Send(encoder.GenerateCommand(Commands.QR_SUCCESS_2, cmd[3], cmd[4], cmd[5]));
}
break;
//收到TRAFFIC_LIGHT指令,开始识别交通灯,回传识别成功的数据
case Commands.RECEIVE_TRAFFIC_LIGHT:
dtc_client.Send(RecognizeTrafficLight());
break;
//收到SHAPE_COLOR指令,开始识别形状颜色,回传识别成功的数据
case Commands.RECEIVE_SHAPE_COLOR:
dtc_client.Send(RecognizeShapeColor());
break;
//收到CAR_ID指令,开始识别车牌号,回传识别成功的数据
case Commands.RECEIVE_CAR_ID:
RecognizeCarID();
break;
//收到TRAFFIC_SIGN指令,开始识别交通标志,回传识别成功的数据
case Commands.RECEIVE_TRAFFIC_SIGN:
dtc_client.Send(RecognizeTrafficSign());
break;
//收到OCR指令,开始识别文本,回传识别成功的数据
case Commands.RECEIVE_TEXT_OCR:
OCRRecognizeText();
break;
//收到未知指令,回传异常指令,表示无法解析当前指令
default:
CommandEncoder error = new CommandEncoder();
dtc_client.Send(error.GenerateCommand(Commands.CMD_NOT_MATCH, (byte) 0x00, (byte) 0x00, (byte) 0x00));
break;
}
});
th_run_command.start();
}
//指令解析失败,回传异常指令,表示无法解析当前指令
else
{
CommandEncoder error = new CommandEncoder();
dtc_client.ThreadSend(error.GenerateCommand(Commands.CMD_NOT_MATCH, (byte) 0x00, (byte) 0x00, (byte) 0x00));
}
}
//收到NULL,输出日志,不做操作
else
ToastLog("NULL Received", true, false);
}
//接收到打印数组的指令,打印数组
//内部消息:打印数组;操作:打印收到的数组
if (msg.what == Flags.PRINT_DATA_ARRAY)
{
byte[] data = (byte[]) msg.obj;
if (data != null)
ToastLog("SEND: [" + ByteArray2String(data) + "]", false, false);
}
//接收到打印日志的指令,打印日志
if(msg.what == Flags.PRINT_SYSTEM_LOG)
//内部消息:打印日志;操作:打印收到的日志
if (msg.what == Flags.PRINT_SYSTEM_LOG)
{
String str = (String)msg.obj;
if(str != null)
String str = (String) msg.obj;
if (str != null)
ToastLog(str, false, false);
}
}
};
}
//处理二维码数据,使用从C++代码中导出的算法
private byte[] ProcessQRData(ArrayList<String> qr_data)
{
return MainCarAES.CalcAES(qr_data.get(0));
}
//获取程序自检指令,根据自检状态返回成功或失败
private byte[] SystemStatusCommand()
{
CommandEncoder encoder = new CommandEncoder();
if(SystemStatus && FileStatus)
if (SystemStatus && FileStatus)
return encoder.GenerateCommand(Commands.STATUS_SUCCESS, (byte) 0, (byte) 0, (byte) 0);
else
return encoder.GenerateCommand(Commands.STATUS_FAILED, (byte) 0, (byte) 0, (byte) 0);
}
//识别二维码
private byte[] RecognizeQrCode()
{
CommandEncoder encoder = new CommandEncoder();
ArrayList<String> qr_result = new ArrayList<>();
if(!QRDecoder.BeginQRDecode(currImage))
if (!QRDecoder.BeginQRDecode(currImage))
return encoder.GenerateCommand(Commands.QR_FAILED, (byte) 0, (byte) 0, (byte) 0);
while(QRDecoder.HasNextCode())
while (QRDecoder.HasNextCode())
qr_result.add(QRDecoder.DecodeNextQR());
if (qr_result.size() <= 0)
return encoder.GenerateCommand(Commands.QR_FAILED, (byte) 0, (byte) 0, (byte) 0);
@@ -215,6 +255,7 @@ public class MainActivity extends AppCompatActivity
}
}
//识别交通灯
private byte[] RecognizeTrafficLight()
{
TrafficLightColors color = TrafficLight.RecognizeTrafficLight(currImage);
@@ -233,6 +274,7 @@ public class MainActivity extends AppCompatActivity
return encoder.GenerateCommand(Commands.TRAFFIC_LIGHT_FAILED, (byte) -1, (byte) -1, (byte) -1);
}
//识别形状颜色
private byte[] RecognizeShapeColor()
{
CommandEncoder encoder = new CommandEncoder();
@@ -241,19 +283,87 @@ public class MainActivity extends AppCompatActivity
else
{
byte a = 0, b = 0, c = 0;
//Add Value to Lookup
//测试用输出
/*ToastLog("C-R-"+ShapeColor.LookupResult(GlobalShape.CIRCLE, GlobalColor.RED), false, false);
ToastLog("C-BL-"+ShapeColor.LookupResult(GlobalShape.CIRCLE, GlobalColor.BLACK), false, false);
ToastLog("C-G-"+ShapeColor.LookupResult(GlobalShape.CIRCLE, GlobalColor.GREEN), false, false);
ToastLog("C-BU-"+ShapeColor.LookupResult(GlobalShape.CIRCLE, GlobalColor.BLUE), false, false);
ToastLog("C-C-"+ShapeColor.LookupResult(GlobalShape.CIRCLE, GlobalColor.CYAN), false, false);
ToastLog("C-P-"+ShapeColor.LookupResult(GlobalShape.CIRCLE, GlobalColor.PURPLE), false, false);
ToastLog("C-W-"+ShapeColor.LookupResult(GlobalShape.CIRCLE, GlobalColor.WHITE), false, false);
ToastLog("C-Y-"+ShapeColor.LookupResult(GlobalShape.CIRCLE, GlobalColor.YELLOW), false, false);
ToastLog("S-R-"+ShapeColor.LookupResult(GlobalShape.STAR, GlobalColor.RED), false, false);
ToastLog("S-BL-"+ShapeColor.LookupResult(GlobalShape.STAR, GlobalColor.BLACK), false, false);
ToastLog("S-G-"+ShapeColor.LookupResult(GlobalShape.STAR, GlobalColor.GREEN), false, false);
ToastLog("S-BU-"+ShapeColor.LookupResult(GlobalShape.STAR, GlobalColor.BLUE), false, false);
ToastLog("S-C-"+ShapeColor.LookupResult(GlobalShape.STAR, GlobalColor.CYAN), false, false);
ToastLog("S-P-"+ShapeColor.LookupResult(GlobalShape.STAR, GlobalColor.PURPLE), false, false);
ToastLog("S-W-"+ShapeColor.LookupResult(GlobalShape.STAR, GlobalColor.WHITE), false, false);
ToastLog("S-Y-"+ShapeColor.LookupResult(GlobalShape.STAR, GlobalColor.YELLOW), false, false);
ToastLog("s-R-"+ShapeColor.LookupResult(GlobalShape.SQUARE, GlobalColor.RED), false, false);
ToastLog("s-BL-"+ShapeColor.LookupResult(GlobalShape.SQUARE, GlobalColor.BLACK), false, false);
ToastLog("s-G-"+ShapeColor.LookupResult(GlobalShape.SQUARE, GlobalColor.GREEN), false, false);
ToastLog("s-BU-"+ShapeColor.LookupResult(GlobalShape.SQUARE, GlobalColor.BLUE), false, false);
ToastLog("s-C-"+ShapeColor.LookupResult(GlobalShape.SQUARE, GlobalColor.CYAN), false, false);
ToastLog("s-P-"+ShapeColor.LookupResult(GlobalShape.SQUARE, GlobalColor.PURPLE), false, false);
ToastLog("s-W-"+ShapeColor.LookupResult(GlobalShape.SQUARE, GlobalColor.WHITE), false, false);
ToastLog("s-Y-"+ShapeColor.LookupResult(GlobalShape.SQUARE, GlobalColor.YELLOW), false, false);
ToastLog("R-R-"+ShapeColor.LookupResult(GlobalShape.RECTANGLE, GlobalColor.RED), false, false);
ToastLog("R-BL-"+ShapeColor.LookupResult(GlobalShape.RECTANGLE, GlobalColor.BLACK), false, false);
ToastLog("R-G-"+ShapeColor.LookupResult(GlobalShape.RECTANGLE, GlobalColor.GREEN), false, false);
ToastLog("R-BU-"+ShapeColor.LookupResult(GlobalShape.RECTANGLE, GlobalColor.BLUE), false, false);
ToastLog("R-C-"+ShapeColor.LookupResult(GlobalShape.RECTANGLE, GlobalColor.CYAN), false, false);
ToastLog("R-P-"+ShapeColor.LookupResult(GlobalShape.RECTANGLE, GlobalColor.PURPLE), false, false);
ToastLog("R-W-"+ShapeColor.LookupResult(GlobalShape.RECTANGLE, GlobalColor.WHITE), false, false);
ToastLog("R-Y-"+ShapeColor.LookupResult(GlobalShape.RECTANGLE, GlobalColor.YELLOW), false, false);
ToastLog("T-R-"+ShapeColor.LookupResult(GlobalShape.TRIANGLE, GlobalColor.RED), false, false);
ToastLog("T-BL-"+ShapeColor.LookupResult(GlobalShape.TRIANGLE, GlobalColor.BLACK), false, false);
ToastLog("T-G-"+ShapeColor.LookupResult(GlobalShape.TRIANGLE, GlobalColor.GREEN), false, false);
ToastLog("T-BU-"+ShapeColor.LookupResult(GlobalShape.TRIANGLE, GlobalColor.BLUE), false, false);
ToastLog("T-C-"+ShapeColor.LookupResult(GlobalShape.TRIANGLE, GlobalColor.CYAN), false, false);
ToastLog("T-P-"+ShapeColor.LookupResult(GlobalShape.TRIANGLE, GlobalColor.PURPLE), false, false);
ToastLog("T-W-"+ShapeColor.LookupResult(GlobalShape.TRIANGLE, GlobalColor.WHITE), false, false);
ToastLog("T-Y-"+ShapeColor.LookupResult(GlobalShape.TRIANGLE, GlobalColor.YELLOW), false, false);*/
return encoder.GenerateCommand(Commands.COLOR_SHAPE_SUCCESS, a, b, c);
}
}
//识别车牌
private void RecognizeCarID()
{
CommandEncoder encoder = new CommandEncoder();
CarLicense.Result result = CarLicense.Recognize(currImage);
if(!result.Success())
// CarLicense.Result result = CarLicense.Recognize(currImage); //通过模板匹配识别车牌
// CarLicense.Result result = CarLicense.RecognizeByOCR(currImage); //通过OCR识别车牌
CarLicense.Result result = CarLicense.RecognizeByAI(currImage, this); //通过AI模型识别车牌
if (!result.Success())
{
//OCR识别的自动重试功能
/*final int OCR_MAX_RETRY = 5;
int retry_time = 0;
do
{
result = CarLicense.RecognizeByOCR(currImage);
Sleep(100);
retry_time++;
}while (result.isEmpty() && (retry_time <= OCR_MAX_RETRY));
if(retry_time > OCR_MAX_RETRY)
dtc_client.Send(encoder.GenerateCommand(Commands.CAR_ID_FAILED, (byte) 0, (byte) 0, (byte) 0));
else
{
encoder.AddMainCommand(Commands.CAR_ID_SUCCESS_FIRST);
encoder.AddData(result.GetFirstThreeBits());
dtc_client.Send(encoder.GenerateCommand());
Sleep(500);
encoder.Clear();
encoder.AddMainCommand(Commands.CAR_ID_SUCCESS_SECOND);
encoder.AddData(result.GetLastThreeBits());
dtc_client.Send(encoder.GenerateCommand());
}*/
dtc_client.Send(encoder.GenerateCommand(Commands.CAR_ID_FAILED, (byte) 0, (byte) 0, (byte) 0));
}
else
{
//车牌信息分两次发送
encoder.AddMainCommand(Commands.CAR_ID_SUCCESS_FIRST);
encoder.AddData(result.GetFirstThreeBits());
dtc_client.Send(encoder.GenerateCommand());
@@ -265,11 +375,12 @@ public class MainActivity extends AppCompatActivity
}
}
//识别交通标志
private byte[] RecognizeTrafficSign()
{
CommandEncoder encoder = new CommandEncoder();
GlobalSignType type = TrafficSign.SignRecognize(currImage);
if(type == GlobalSignType.Failure)
if (type == GlobalSignType.Failure)
return encoder.GenerateCommand(Commands.TRAFFIC_SIGN_FAILED, (byte) 0, (byte) 0, (byte) 0);
else
{
@@ -299,10 +410,12 @@ public class MainActivity extends AppCompatActivity
}
}
//识别静态文本
private void OCRRecognizeText()
{
// String str = OCR.DecodeImage(currImage);
String str = OCR.SelfTest(this);
TextFilter filter = new TextFilter();
String str = filter.RemoveEmptyCharacter(OCR.DecodeImage(currImage));
ToastLog("OCR Result: [" + str + "]", false, true);
byte[] b_str;
try
{
@@ -317,18 +430,23 @@ public class MainActivity extends AppCompatActivity
}
CommandEncoder encoder = new CommandEncoder();
dtc_client.Send(encoder.GenerateCommand(Commands.OCR_TEXT_SUCCESS, (byte) 0x00, (byte) 0x00, (byte) 0x00));
Sleep(500);
Sleep(900);
dtc_client.Send(encoder.GenerateCommand(Commands.OCR_TEXT_LENGTH, (byte) b_str.length, (byte) 0x00, (byte) b_str.length));
for (int i = 0; i < b_str.length; i += 2)
{
Sleep(500);
byte data_2 = ((i + 1) >= b_str.length ? 0x00 : b_str[i + 1]);
byte checksum = (byte) ((b_str[i] + data_2) % 0xFF);
byte main = ((i + 1) < b_str.length ? Commands.OCR_TEXT_DATA : Commands.OCR_TEXT_FINISH);
dtc_client.Send(encoder.GenerateCommand(main, b_str[i], data_2, checksum));
byte main = ((i + 2) < b_str.length ? Commands.OCR_TEXT_DATA : Commands.OCR_TEXT_FINISH);
if (!dtc_client.SendEx(encoder.GenerateCommand(main, b_str[i], data_2, checksum), Commands.RECEIVE_OCR_DATA_OK, 2000))
{
dtc_client.Send(encoder.GenerateCommand(Commands.OCR_TEXT_FAILED, (byte) 0x00, (byte) 0x00, (byte) 0x00));
break;
}
}
}
//数组转字符串,仅用于调试输出
private String ByteArray2String(byte[] arr)
{
StringBuilder msg_str = new StringBuilder();
@@ -337,6 +455,7 @@ public class MainActivity extends AppCompatActivity
return msg_str.toString();
}
//初始化图形界面
private void InitGUI()
{
pic_received = findViewById(R.id.camera_image);
@@ -376,7 +495,7 @@ public class MainActivity extends AppCompatActivity
findViewById(R.id.btn_send).setOnClickListener(view ->
{
Thread th_send = new Thread(() ->
try
{
byte cmd0 = (byte) Integer.parseInt(((EditText) findViewById(R.id.edit_cmd0)).getText().toString(), 16);
byte cmd1 = (byte) Integer.parseInt(((EditText) findViewById(R.id.edit_cmd1)).getText().toString(), 16);
@@ -384,64 +503,95 @@ public class MainActivity extends AppCompatActivity
byte cmd3 = (byte) Integer.parseInt(((EditText) findViewById(R.id.edit_cmd3)).getText().toString(), 16);
CommandEncoder encoder = new CommandEncoder();
byte[] cmd = encoder.GenerateCommand(cmd0, cmd1, cmd2, cmd3);
dtc_client.Send(cmd);
dtc_client.ThreadSend(cmd);
//print debug information
Message.obtain(recvHandler, Flags.PRINT_DATA_ARRAY, cmd).sendToTarget();
});
th_send.start();
}
catch (Exception e)
{
ToastLog("Input Data Invalidate", true, false);
}
});
findViewById(R.id.btn_start_qr).setOnClickListener(view -> {
findViewById(R.id.btn_start_qr).setOnClickListener(view ->
{
ToastLog("QR Code Started", false, false);
ToastLog("QR Result: " + ByteArray2String(RecognizeQrCode()), false, false);
});
findViewById(R.id.btn_start_light).setOnClickListener(view -> {
findViewById(R.id.btn_start_light).setOnClickListener(view ->
{
ToastLog("Traffic Light Started", false, false);
ToastLog("TL Result: " + ByteArray2String(RecognizeTrafficLight()), false, false);
});
findViewById(R.id.btn_start_color_shape).setOnClickListener(view -> {
findViewById(R.id.btn_start_color_shape).setOnClickListener(view ->
{
ToastLog("Color Shape Started", false, false);
ToastLog("CS Result: " + ByteArray2String(RecognizeShapeColor()), false, false);
});
findViewById(R.id.btn_start_car_id).setOnClickListener(view -> {
findViewById(R.id.btn_start_car_id).setOnClickListener(view ->
{
ToastLog("Car ID Started", false, false);
Thread th_debug = new Thread(this::RecognizeCarID);
th_debug.start();
ToastLog("CID Finished", false, false);
});
findViewById(R.id.btn_start_sign).setOnClickListener(view -> {
findViewById(R.id.btn_start_sign).setOnClickListener(view ->
{
ToastLog("Traffic Sign Started", false, false);
ToastLog("TS Result: " + ByteArray2String(RecognizeTrafficSign()), false, false);
});
findViewById(R.id.btn_start_ocr).setOnClickListener(view -> {
findViewById(R.id.btn_start_ocr).setOnClickListener(view ->
{
ToastLog("OCR Started", false, false);
/*ToastLog("OCR Result: " + OCR.DecodeImage(currImage), false, false);*/
Thread th_debug = new Thread(this::OCRRecognizeText);
th_debug.start();
});
findViewById(R.id.btn_tft_page_down).setOnClickListener(view -> {
findViewById(R.id.btn_tft_page_down).setOnClickListener(view ->
{
CommandEncoder encoder = new CommandEncoder();
dtc_client.ThreadSend(encoder.GenerateCommand(Commands.TFT_PAGE_DOWN, (byte) 0, (byte) 0, (byte) 0));
ToastLog("TFT Page Down Command Send.", false, true);
});
findViewById(R.id.btn_movement_control).setOnClickListener(view -> {
findViewById(R.id.btn_movement_control).setOnClickListener(view ->
{
startActivity(new Intent(this, MovementController.class));
});
findViewById(R.id.btn_crash).setOnClickListener(view -> {
findViewById(R.id.btn_crash).setOnClickListener(view ->
{
//崩溃按钮的作用:频繁调试时省去手动退出程序,清理后台的操作,节省时间。
dtc_client.CloseConnection(); //关闭通信
throw new NullPointerException(); //通过异常来崩溃。
dtc_client.DisableAutoReconnect();
dtc_client.CloseConnection(); //关闭通信
throw new NullPointerException(); //通过异常来崩溃。
});
findViewById(R.id.text_toast).setOnLongClickListener(view ->
{
ToastLog("Log Cleared", true, false);
((TextView) view).setText("");
return true;
});
findViewById(R.id.camera_image).setOnLongClickListener(view ->
{
String time = String.valueOf(System.currentTimeMillis());
if (SaveImage(currImage, time))
ToastLog("Image Saved", true, false);
else
ToastLog("Image Save Failure", true, false);
return true;
});
}
//打印日志
@SuppressLint("SetTextI18n")
private void ToastLog(String text, boolean real_toast, boolean on_thread)
{
@@ -450,12 +600,13 @@ public class MainActivity extends AppCompatActivity
if (real_toast)
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
Log.i("ToastBackup", text);
if(on_thread)
if (on_thread)
Message.obtain(recvHandler, Flags.PRINT_SYSTEM_LOG, text);
else
text_toast.setText(text_toast.getText().toString() + "\n" + text);
}
//等待一段时间
private void Sleep(long ms)
{
try
@@ -467,6 +618,7 @@ public class MainActivity extends AppCompatActivity
}
}
//启动寻找摄像头的线程
private void StartCameraImageUpdate(int duration)
{
Thread th_image = new Thread(() ->
@@ -508,10 +660,10 @@ public class MainActivity extends AppCompatActivity
ToastLog(EnvTest.TestMainCarAES(), false, false);
byte[] demo = MainCarAES.CalcAES("ABCDEFGHabcdefgh");
if(demo == null)
ToastLog("AES Status: Error",false,false);
if (demo == null)
ToastLog("AES Status: Error", false, false);
else
ToastLog("AES Status: " + ByteArray2String(demo),false,false);
ToastLog("AES Status: " + ByteArray2String(demo), false, false);
//二维码扫描自检
ToastLog(QRDecoder.SelfTest(BitmapFactory.decodeResource(getResources(), R.drawable.qr_decode_test)), false, false);
@@ -523,20 +675,21 @@ public class MainActivity extends AppCompatActivity
ToastLog("DHCP Server Address: " + IPCar, false, false);
//建立连接
if(CommunicationUsingWifi)
dtc_client = new WifiTransferCore(IPCar,60000, recvHandler);
if (CommunicationUsingWifi)
dtc_client = new WifiTransferCore(IPCar, 60000, recvHandler);
else
dtc_client = new SerialPortTransferCore(SerialPortPath, 115200, recvHandler);
Thread th_connect = new Thread(() -> {
if(dtc_client.Connect())
Thread th_connect = new Thread(() ->
{
if (dtc_client.Connect())
ToastLog("Client Connected", false, true);
else
ToastLog("Client Connect Failed", false, true);
});
th_connect.start();
while(th_connect.isAlive())
while (th_connect.isAlive())
Sleep(10); //Wait for Connection Thread
dtc_client.EnableAutoReconnect(); //启动自动重连
dtc_client.EnableAutoReconnect(); //启动自动重连
//初始化摄像头控制
cameraCommandUtil = new CameraCommandUtil();
@@ -577,17 +730,17 @@ public class MainActivity extends AppCompatActivity
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == permission_request_code)
if (requestCode == permission_request_code)
{
if(resultCode == RESULT_OK)
if (resultCode == RESULT_OK)
{
ImageReleaser releaser = new ImageReleaser(this);
OCRDataReleaser releaser_ocr = new OCRDataReleaser(this);
FileStatus = (releaser.ReleaseAllImage() && releaser_ocr.ReleaseAllFiles());
ToastLog(releaser.toString(), false, false);
ToastLog(releaser_ocr.toString(), false, false);
if(FileStatus)
ToastLog(OCR.SelfTest(this), false, false); //OCR光学字符识别自检
if (FileStatus)
ToastLog(OCR.SelfTest(this), false, false); //OCR光学字符识别自检
}
else
FileStatus = false;
@@ -598,6 +751,7 @@ public class MainActivity extends AppCompatActivity
protected void onDestroy()
{
super.onDestroy();
//Activity销毁时关闭通信
dtc_client.DisableAutoReconnect();
dtc_client.CloseConnection();
}