commit after race
This commit is contained in:
@@ -39,6 +39,8 @@ public class Commands
|
||||
|
||||
//形状颜色
|
||||
public static byte COLOR_SHAPE_SUCCESS = (byte) 0xA6;
|
||||
public static byte COLOR_SHAPE_DATA_PART2 = (byte) 0xC6;
|
||||
public static byte COLOR_SHAPE_DATA_PART3 = (byte) 0xD6;
|
||||
public static byte COLOR_SHAPE_FAILED = (byte) 0xB6;
|
||||
|
||||
//交通标志
|
||||
|
||||
@@ -19,6 +19,18 @@ public class Flags
|
||||
public static final int CAMERA_DOWN = 2;
|
||||
public static final int CAMERA_LEFT = 4;
|
||||
public static final int CAMERA_RIGHT = 6;
|
||||
public static final int CAMERA_STEP_0 = 0;
|
||||
public static final int CAMERA_STEP_1 = 1;
|
||||
public static final int CAMERA_STEP_2 = 2;
|
||||
public static final int CAMERA_RE_INIT = 2;
|
||||
public static final int CAMERA_SET_POS_1 = 32;
|
||||
public static final int CAMERA_GET_POS_1 = 33;
|
||||
public static final int CAMERA_SET_POS_2 = 34;
|
||||
public static final int CAMERA_GET_POS_2 = 35;
|
||||
public static final int CAMERA_SET_POS_3 = 36;
|
||||
public static final int CAMERA_GET_POS_3 = 37;
|
||||
public static final int CAMERA_SET_POS_4 = 38;
|
||||
public static final int CAMERA_GET_POS_4 = 39;
|
||||
|
||||
//主/从车移动控制指令
|
||||
public static final byte CMD_PACKET_MAIN_CAR = (byte) 0xAA;
|
||||
|
||||
@@ -57,11 +57,51 @@ public class ShapeColorResult
|
||||
if (storage.containsKey(color) && Objects.requireNonNull(storage.get(color)).containsKey(shape))
|
||||
return Objects.requireNonNull(Objects.requireNonNull(storage.get(color)).get(shape));
|
||||
else
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return -2;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int GetValue(GlobalColor color)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (storage.containsKey(color))
|
||||
{
|
||||
AtomicInteger cnt = new AtomicInteger();
|
||||
HashMap<GlobalShape, Integer> spec_color = storage.get(color);
|
||||
if (spec_color == null)
|
||||
return 0;
|
||||
spec_color.forEach((s, c) -> cnt.addAndGet(c));
|
||||
return cnt.intValue();
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int GetValue(GlobalShape shape)
|
||||
{
|
||||
try
|
||||
{
|
||||
AtomicInteger cnt = new AtomicInteger();
|
||||
storage.forEach((c, map) -> map.forEach((s, _c) ->
|
||||
{
|
||||
if (s == shape)
|
||||
cnt.addAndGet(_c);
|
||||
}));
|
||||
return cnt.intValue();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ import com.uns.maincar.constants.Commands;
|
||||
import com.uns.maincar.constants.Flags;
|
||||
import com.uns.maincar.constants.Flags.TrafficLightColors;
|
||||
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.ColoredQRDecoder;
|
||||
import com.uns.maincar.cpp_interface.EnvTest;
|
||||
@@ -72,7 +73,7 @@ public class MainActivity extends AppCompatActivity
|
||||
//数据接收处理器
|
||||
private final Handler recvHandler;
|
||||
//主车相机地址,默认值不重要
|
||||
private String IPCamera = "192.168.1.101:81";
|
||||
private String IPCamera = "10.254.254.100";
|
||||
//摄像头当前图像
|
||||
private Bitmap currImage;
|
||||
//存储小车的IP
|
||||
@@ -199,7 +200,7 @@ public class MainActivity extends AppCompatActivity
|
||||
break;
|
||||
//收到SHAPE_COLOR指令,开始识别形状颜色,回传识别成功的数据
|
||||
case Commands.RECEIVE_SHAPE_COLOR:
|
||||
dtc_client.Send(RecognizeShapeColor());
|
||||
RecognizeShapeColor();
|
||||
break;
|
||||
//收到CAR_ID指令,开始识别车牌号,回传识别成功的数据
|
||||
case Commands.RECEIVE_CAR_ID:
|
||||
@@ -249,7 +250,7 @@ public class MainActivity extends AppCompatActivity
|
||||
TextFilter filter = new TextFilter();
|
||||
for (String data : qr_data)
|
||||
{
|
||||
String processed_data = filter.LetterAndNumber(data);
|
||||
String processed_data = filter.ChineseOnly(data);
|
||||
if (processed_data.length() > 0)
|
||||
{
|
||||
validate_result = processed_data;
|
||||
@@ -285,9 +286,11 @@ public class MainActivity extends AppCompatActivity
|
||||
//识别二维码
|
||||
private byte[] RecognizeQrCode(boolean colored, GlobalColor target_color)
|
||||
{
|
||||
ToastLog("Begin QR Code", false, true);
|
||||
CommandEncoder encoder = new CommandEncoder();
|
||||
if (!colored)
|
||||
{
|
||||
ToastLog("Start Black-White QR", false, true);
|
||||
ArrayList<String> qr_result = new ArrayList<>();
|
||||
if (!QRDecoder.BeginQRDecode(currImage))
|
||||
return encoder.GenerateCommand(Commands.QR_FAILED, (byte) 0, (byte) 0, (byte) 0);
|
||||
@@ -296,10 +299,7 @@ public class MainActivity extends AppCompatActivity
|
||||
if (qr_result.size() <= 0)
|
||||
return encoder.GenerateCommand(Commands.QR_FAILED, (byte) 0, (byte) 0, (byte) 0);
|
||||
else
|
||||
{
|
||||
qr_result.forEach(qr -> ToastLog(qr, false, true));
|
||||
return ProcessQRData(qr_result);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -343,7 +343,7 @@ public class MainActivity extends AppCompatActivity
|
||||
}
|
||||
|
||||
//识别形状颜色
|
||||
private byte[] RecognizeShapeColor()
|
||||
private void RecognizeShapeColor()
|
||||
{
|
||||
CommandEncoder encoder = new CommandEncoder();
|
||||
/*if (!ShapeColor.RecognizeEverything(currImage))
|
||||
@@ -358,8 +358,20 @@ public class MainActivity extends AppCompatActivity
|
||||
ShapeDetector detector = new ShapeDetector();
|
||||
detector.shapePicProcess(currImage);
|
||||
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);
|
||||
return encoder.GenerateCommand();
|
||||
}
|
||||
|
||||
//识别车牌
|
||||
@@ -659,7 +671,7 @@ public class MainActivity extends AppCompatActivity
|
||||
{
|
||||
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);
|
||||
});
|
||||
th_send.start();
|
||||
@@ -669,7 +681,7 @@ public class MainActivity extends AppCompatActivity
|
||||
{
|
||||
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);
|
||||
});
|
||||
th_send.start();
|
||||
@@ -679,7 +691,7 @@ public class MainActivity extends AppCompatActivity
|
||||
{
|
||||
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);
|
||||
});
|
||||
th_send.start();
|
||||
@@ -689,7 +701,7 @@ public class MainActivity extends AppCompatActivity
|
||||
{
|
||||
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);
|
||||
});
|
||||
th_send.start();
|
||||
@@ -737,7 +749,8 @@ public class MainActivity extends AppCompatActivity
|
||||
context.findViewById(R.id.btn_start_color_shape).setOnClickListener(view ->
|
||||
{
|
||||
ToastLog("Color Shape Started", false, false);
|
||||
ToastLog("CS Result: " + ByteArray2String(RecognizeShapeColor()), false, false);
|
||||
ToastLog("CS Result: ", false, false);
|
||||
RecognizeShapeColor();
|
||||
context.finish();
|
||||
});
|
||||
|
||||
@@ -938,7 +951,7 @@ public class MainActivity extends AppCompatActivity
|
||||
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);
|
||||
|
||||
//初始化开源车型识别库
|
||||
@@ -981,7 +994,6 @@ public class MainActivity extends AppCompatActivity
|
||||
while (!success); //避免”while循环具有空体“警告
|
||||
IPCamera = cameraSearcher.GetCameraIP();
|
||||
ToastLog("CameraSearchThread: Camera Found. IP: " + IPCamera, false, true);
|
||||
IPCamera += ":81";
|
||||
ToastLog("Camera Address: " + IPCamera, false, true);
|
||||
StartCameraImageUpdate(50);
|
||||
//这里是程序初始化的最后一步,能到达此处标志着自检通过
|
||||
|
||||
@@ -22,11 +22,13 @@ import java.net.URL;
|
||||
|
||||
public class CameraOperator
|
||||
{
|
||||
private static final String Port = "100";
|
||||
|
||||
public static Bitmap GetImage(String IP)
|
||||
{
|
||||
try
|
||||
{
|
||||
URL url = new URL("http://" + IP + "/snapshot.cgi?loginuse=admin&loginpas=888888&res=0");
|
||||
URL url = new URL("http://" + IP + ":" + Port + "/snapshot.cgi?loginuse=admin&loginpas=888888&res=0");
|
||||
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
|
||||
httpURLConnection.setDoInput(true);
|
||||
httpURLConnection.connect();
|
||||
@@ -48,7 +50,7 @@ public class CameraOperator
|
||||
return false;
|
||||
try
|
||||
{
|
||||
URL url = new URL("http://" + IP + "/decoder_control.cgi?loginuse=admin&loginpas=888888&" + "command=" + command + "&onestep=" + step);
|
||||
URL url = new URL("http://" + IP + ":" + Port + "/decoder_control.cgi?loginuse=admin&loginpas=888888&command=" + command + "&onestep=" + step);
|
||||
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
|
||||
urlConnection.connect();
|
||||
urlConnection.disconnect();
|
||||
|
||||
Reference in New Issue
Block a user