|
|
@ -43,6 +43,7 @@ import com.uns.maincar.constants.Commands;
|
|
|
|
import com.uns.maincar.constants.Flags;
|
|
|
|
import com.uns.maincar.constants.Flags;
|
|
|
|
import com.uns.maincar.constants.Flags.TrafficLightColors;
|
|
|
|
import com.uns.maincar.constants.Flags.TrafficLightColors;
|
|
|
|
import com.uns.maincar.constants.GlobalColor;
|
|
|
|
import com.uns.maincar.constants.GlobalColor;
|
|
|
|
|
|
|
|
import com.uns.maincar.constants.GlobalShape;
|
|
|
|
import com.uns.maincar.cpp_interface.CarLicense;
|
|
|
|
import com.uns.maincar.cpp_interface.CarLicense;
|
|
|
|
import com.uns.maincar.cpp_interface.ColoredQRDecoder;
|
|
|
|
import com.uns.maincar.cpp_interface.ColoredQRDecoder;
|
|
|
|
import com.uns.maincar.cpp_interface.EnvTest;
|
|
|
|
import com.uns.maincar.cpp_interface.EnvTest;
|
|
|
@ -72,7 +73,7 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
//数据接收处理器
|
|
|
|
//数据接收处理器
|
|
|
|
private final Handler recvHandler;
|
|
|
|
private final Handler recvHandler;
|
|
|
|
//主车相机地址,默认值不重要
|
|
|
|
//主车相机地址,默认值不重要
|
|
|
|
private String IPCamera = "192.168.1.101:81";
|
|
|
|
private String IPCamera = "10.254.254.100";
|
|
|
|
//摄像头当前图像
|
|
|
|
//摄像头当前图像
|
|
|
|
private Bitmap currImage;
|
|
|
|
private Bitmap currImage;
|
|
|
|
//存储小车的IP
|
|
|
|
//存储小车的IP
|
|
|
@ -199,7 +200,7 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
//收到SHAPE_COLOR指令,开始识别形状颜色,回传识别成功的数据
|
|
|
|
//收到SHAPE_COLOR指令,开始识别形状颜色,回传识别成功的数据
|
|
|
|
case Commands.RECEIVE_SHAPE_COLOR:
|
|
|
|
case Commands.RECEIVE_SHAPE_COLOR:
|
|
|
|
dtc_client.Send(RecognizeShapeColor());
|
|
|
|
RecognizeShapeColor();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
//收到CAR_ID指令,开始识别车牌号,回传识别成功的数据
|
|
|
|
//收到CAR_ID指令,开始识别车牌号,回传识别成功的数据
|
|
|
|
case Commands.RECEIVE_CAR_ID:
|
|
|
|
case Commands.RECEIVE_CAR_ID:
|
|
|
@ -249,7 +250,7 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
TextFilter filter = new TextFilter();
|
|
|
|
TextFilter filter = new TextFilter();
|
|
|
|
for (String data : qr_data)
|
|
|
|
for (String data : qr_data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
String processed_data = filter.LetterAndNumber(data);
|
|
|
|
String processed_data = filter.ChineseOnly(data);
|
|
|
|
if (processed_data.length() > 0)
|
|
|
|
if (processed_data.length() > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
validate_result = processed_data;
|
|
|
|
validate_result = processed_data;
|
|
|
@ -285,9 +286,11 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
//识别二维码
|
|
|
|
//识别二维码
|
|
|
|
private byte[] RecognizeQrCode(boolean colored, GlobalColor target_color)
|
|
|
|
private byte[] RecognizeQrCode(boolean colored, GlobalColor target_color)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
ToastLog("Begin QR Code", false, true);
|
|
|
|
CommandEncoder encoder = new CommandEncoder();
|
|
|
|
CommandEncoder encoder = new CommandEncoder();
|
|
|
|
if (!colored)
|
|
|
|
if (!colored)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
ToastLog("Start Black-White QR", false, true);
|
|
|
|
ArrayList<String> qr_result = new ArrayList<>();
|
|
|
|
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);
|
|
|
|
return encoder.GenerateCommand(Commands.QR_FAILED, (byte) 0, (byte) 0, (byte) 0);
|
|
|
@ -296,11 +299,8 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
if (qr_result.size() <= 0)
|
|
|
|
if (qr_result.size() <= 0)
|
|
|
|
return encoder.GenerateCommand(Commands.QR_FAILED, (byte) 0, (byte) 0, (byte) 0);
|
|
|
|
return encoder.GenerateCommand(Commands.QR_FAILED, (byte) 0, (byte) 0, (byte) 0);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
qr_result.forEach(qr -> ToastLog(qr, false, true));
|
|
|
|
|
|
|
|
return ProcessQRData(qr_result);
|
|
|
|
return ProcessQRData(qr_result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
boolean success = ColoredQRDecoder.BeginQRDecode(currImage, false);
|
|
|
|
boolean success = ColoredQRDecoder.BeginQRDecode(currImage, false);
|
|
|
@ -343,7 +343,7 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//识别形状颜色
|
|
|
|
//识别形状颜色
|
|
|
|
private byte[] RecognizeShapeColor()
|
|
|
|
private void RecognizeShapeColor()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CommandEncoder encoder = new CommandEncoder();
|
|
|
|
CommandEncoder encoder = new CommandEncoder();
|
|
|
|
/*if (!ShapeColor.RecognizeEverything(currImage))
|
|
|
|
/*if (!ShapeColor.RecognizeEverything(currImage))
|
|
|
@ -358,8 +358,20 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
ShapeDetector detector = new ShapeDetector();
|
|
|
|
ShapeDetector detector = new ShapeDetector();
|
|
|
|
detector.shapePicProcess(currImage);
|
|
|
|
detector.shapePicProcess(currImage);
|
|
|
|
ShapeColorResult result = detector.GetAllResult();
|
|
|
|
ShapeColorResult result = detector.GetAllResult();
|
|
|
|
|
|
|
|
byte blue_latter = (byte) result.GetValue(GlobalColor.BLUE, GlobalShape.RECTANGLE);
|
|
|
|
|
|
|
|
byte red_circle = (byte) result.GetValue(GlobalColor.RED, GlobalShape.CIRCLE);
|
|
|
|
|
|
|
|
byte yellow_triangle = (byte) result.GetValue(GlobalColor.YELLOW, GlobalShape.TRIANGLE);
|
|
|
|
|
|
|
|
byte all_squares = (byte) result.GetValue(GlobalShape.SQUARE);
|
|
|
|
|
|
|
|
byte all_cyan = (byte) result.GetValue(GlobalColor.CYAN);
|
|
|
|
|
|
|
|
byte all_purple = (byte) result.GetValue(GlobalColor.PURPLE);
|
|
|
|
|
|
|
|
byte all_green = (byte) result.GetValue(GlobalColor.GREEN);
|
|
|
|
|
|
|
|
byte all_red = (byte) result.GetValue(GlobalColor.RED);
|
|
|
|
|
|
|
|
dtc_client.Send(encoder.GenerateCommand(Commands.COLOR_SHAPE_DATA_PART3, all_purple, all_green, all_red));
|
|
|
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
dtc_client.Send(encoder.GenerateCommand(Commands.COLOR_SHAPE_SUCCESS, blue_latter, red_circle, yellow_triangle));
|
|
|
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
dtc_client.Send(encoder.GenerateCommand(Commands.COLOR_SHAPE_DATA_PART2, all_squares, (byte) 0x00, all_cyan));
|
|
|
|
ToastLog(result.toString(), false, true);
|
|
|
|
ToastLog(result.toString(), false, true);
|
|
|
|
return encoder.GenerateCommand();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//识别车牌
|
|
|
|
//识别车牌
|
|
|
@ -659,7 +671,7 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Thread th_send = new Thread(() ->
|
|
|
|
Thread th_send = new Thread(() ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!CameraOperator.SendCommand(IPCamera, Flags.CAMERA_UP, 5))
|
|
|
|
if (!CameraOperator.SendCommand(IPCamera, Flags.CAMERA_UP, Flags.CAMERA_STEP_2))
|
|
|
|
ToastLog("Camera Command (UP) Failure.", false, true);
|
|
|
|
ToastLog("Camera Command (UP) Failure.", false, true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
th_send.start();
|
|
|
|
th_send.start();
|
|
|
@ -669,7 +681,7 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Thread th_send = new Thread(() ->
|
|
|
|
Thread th_send = new Thread(() ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!CameraOperator.SendCommand(IPCamera, Flags.CAMERA_DOWN, 5))
|
|
|
|
if (!CameraOperator.SendCommand(IPCamera, Flags.CAMERA_DOWN, Flags.CAMERA_STEP_2))
|
|
|
|
ToastLog("Camera Command (DOWN) Failure.", false, true);
|
|
|
|
ToastLog("Camera Command (DOWN) Failure.", false, true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
th_send.start();
|
|
|
|
th_send.start();
|
|
|
@ -679,7 +691,7 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Thread th_send = new Thread(() ->
|
|
|
|
Thread th_send = new Thread(() ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!CameraOperator.SendCommand(IPCamera, Flags.CAMERA_LEFT, 5))
|
|
|
|
if (!CameraOperator.SendCommand(IPCamera, Flags.CAMERA_LEFT, Flags.CAMERA_STEP_2))
|
|
|
|
ToastLog("Camera Command (LEFT) Failure.", false, true);
|
|
|
|
ToastLog("Camera Command (LEFT) Failure.", false, true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
th_send.start();
|
|
|
|
th_send.start();
|
|
|
@ -689,7 +701,7 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Thread th_send = new Thread(() ->
|
|
|
|
Thread th_send = new Thread(() ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!CameraOperator.SendCommand(IPCamera, Flags.CAMERA_RIGHT, 5))
|
|
|
|
if (!CameraOperator.SendCommand(IPCamera, Flags.CAMERA_RIGHT, Flags.CAMERA_STEP_2))
|
|
|
|
ToastLog("Camera Command (RIGHT) Failure.", false, true);
|
|
|
|
ToastLog("Camera Command (RIGHT) Failure.", false, true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
th_send.start();
|
|
|
|
th_send.start();
|
|
|
@ -737,7 +749,8 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
context.findViewById(R.id.btn_start_color_shape).setOnClickListener(view ->
|
|
|
|
context.findViewById(R.id.btn_start_color_shape).setOnClickListener(view ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ToastLog("Color Shape Started", false, false);
|
|
|
|
ToastLog("Color Shape Started", false, false);
|
|
|
|
ToastLog("CS Result: " + ByteArray2String(RecognizeShapeColor()), false, false);
|
|
|
|
ToastLog("CS Result: ", false, false);
|
|
|
|
|
|
|
|
RecognizeShapeColor();
|
|
|
|
context.finish();
|
|
|
|
context.finish();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -938,7 +951,7 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
ToastLog(QRDecoder.SelfTest(BitmapFactory.decodeResource(getResources(), R.drawable.qr_decode_test)), false, false);
|
|
|
|
ToastLog(QRDecoder.SelfTest(BitmapFactory.decodeResource(getResources(), R.drawable.qr_decode_test)), false, false);
|
|
|
|
|
|
|
|
|
|
|
|
//初始化开源交通标志识别库
|
|
|
|
//初始化开源交通标志识别库
|
|
|
|
YoloV5_tfLite_TSDetector.minimumConfidence = 0.7f;
|
|
|
|
YoloV5_tfLite_TSDetector.minimumConfidence = 0.8f;
|
|
|
|
ToastLog("Open Source Traffic Sign Detector: " + (TS_Detector.LoadModel("CPU", 4, this.getAssets()) ? "Success" : "Failure"), false, false);
|
|
|
|
ToastLog("Open Source Traffic Sign Detector: " + (TS_Detector.LoadModel("CPU", 4, this.getAssets()) ? "Success" : "Failure"), false, false);
|
|
|
|
|
|
|
|
|
|
|
|
//初始化开源车型识别库
|
|
|
|
//初始化开源车型识别库
|
|
|
@ -981,7 +994,6 @@ public class MainActivity extends AppCompatActivity
|
|
|
|
while (!success); //避免”while循环具有空体“警告
|
|
|
|
while (!success); //避免”while循环具有空体“警告
|
|
|
|
IPCamera = cameraSearcher.GetCameraIP();
|
|
|
|
IPCamera = cameraSearcher.GetCameraIP();
|
|
|
|
ToastLog("CameraSearchThread: Camera Found. IP: " + IPCamera, false, true);
|
|
|
|
ToastLog("CameraSearchThread: Camera Found. IP: " + IPCamera, false, true);
|
|
|
|
IPCamera += ":81";
|
|
|
|
|
|
|
|
ToastLog("Camera Address: " + IPCamera, false, true);
|
|
|
|
ToastLog("Camera Address: " + IPCamera, false, true);
|
|
|
|
StartCameraImageUpdate(50);
|
|
|
|
StartCameraImageUpdate(50);
|
|
|
|
//这里是程序初始化的最后一步,能到达此处标志着自检通过
|
|
|
|
//这里是程序初始化的最后一步,能到达此处标志着自检通过
|
|
|
|