feat: 1. 道路自动拍摄多任务判定 2. 道路任务自动录像任务语音提示

This commit is contained in:
xiaoyan 2022-09-22 19:24:32 +08:00
parent 52cd04a466
commit 1b6024d0cb
4 changed files with 98 additions and 40 deletions

View File

@ -11,6 +11,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.location.Location; import android.location.Location;
import android.media.MediaPlayer;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@ -182,7 +183,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
private List<Removable> removables; // 地图上渲染的网络获取的道路任务 private List<Removable> removables; // 地图上渲染的网络获取的道路任务
private List<Removable> removablesLocality; // 地图上渲染的本地道路任务 private List<Removable> removablesLocality; // 地图上渲染的本地道路任务
private HashMap<String, List<Marker>> removableHashMap; private HashMap<String, List<Marker>> removableHashMap;
private List<RoadMatchEntity> roadLinkEntityList, roadMatchEntityList; private List<RoadMatchEntity> roadLinkEntityList/*请求到的待匹配道路数据*/, roadMatchEntityList/*已匹配起始点的道路数据*/;
private int satelliteCount; // 卫星颗数 private int satelliteCount; // 卫星颗数
private final long UN_MATCH_TIME_MAX=30*1000; // 未匹配到的时间阈值最长为30秒 private final long UN_MATCH_TIME_MAX=30*1000; // 未匹配到的时间阈值最长为30秒
private static double MATCH_BUFFER_DISTANCE=15e-5; // 匹配途经点用到的buffer距离此处5米使用简易判断 private static double MATCH_BUFFER_DISTANCE=15e-5; // 匹配途经点用到的buffer距离此处5米使用简易判断
@ -202,6 +203,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
private boolean locationEnable=true; private boolean locationEnable=true;
private ImageView imgViewSettingHook; // 调起隐藏设置的按钮 private ImageView imgViewSettingHook; // 调起隐藏设置的按钮
private TencentLocation oldCurrentLocation = null; private TencentLocation oldCurrentLocation = null;
private MediaPlayer mediaPlayer;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -211,6 +213,8 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
// 设置当前界面亮度为40% // 设置当前界面亮度为40%
setWindowBrightness(BRIGHTNESS); setWindowBrightness(BRIGHTNESS);
// 初始化提示音播放器
mediaPlayer=MediaPlayer.create(this, R.raw.ding);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
} }
@ -650,7 +654,9 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
matchStartDistance = MATCH_BUFFER_DISTANCE*1.5; matchStartDistance = MATCH_BUFFER_DISTANCE*1.5;
} }
// 此处开始匹配起点 // 此处开始匹配起点
List<RoadMatchEntity> matchStartList = roadLinkEntityList.stream().filter(it-> GeometryTools.createGeometry(it.getsPoint()).distance(currentPoint)<MATCH_START_BUFFER_DISTANCE).collect(Collectors.toList()); List<RoadMatchEntity> matchStartList = roadLinkEntityList.stream()
.filter(it-> GeometryTools.createGeometry(it.getsPoint()).distance(currentPoint)<MATCH_START_BUFFER_DISTANCE)
.collect(Collectors.toList());
// 判断筛选出的数据是否已经在匹配列表中如果不存在需要自动领取该任务记录开始采集时间 // 判断筛选出的数据是否已经在匹配列表中如果不存在需要自动领取该任务记录开始采集时间
matchStartList = matchStartList.stream().filter( matchStartList = matchStartList.stream().filter(
o -> roadMatchEntityList.stream().noneMatch(roadMatchEntity -> o.getId()==roadMatchEntity.getId()) o -> roadMatchEntityList.stream().noneMatch(roadMatchEntity -> o.getId()==roadMatchEntity.getId())
@ -664,54 +670,91 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
// TODO:自动发送请求领取任务 // TODO:自动发送请求领取任务
receiverRoadTask(roadMatchEntity).subscribe(receiveObserver); receiverRoadTask(roadMatchEntity).subscribe(receiveObserver);
}); });
// 语音提醒
if (roadMatchEntityList.isEmpty()) {
// 当前没有已匹配的数据提示用户~捕捉任务
mediaPlayer.start();
systemTTS.playText("捕捉任务");
} else {
// 当前存在已匹配的任务有新匹配的任务提示~任务拍摄中
mediaPlayer.start();
systemTTS.playText("任务拍摄中");
}
// 将匹配到的数据加入到已匹配列表中 // 将匹配到的数据加入到已匹配列表中
roadMatchEntityList.addAll(matchStartList); roadMatchEntityList.addAll(matchStartList);
} }
// 尝试用当前位置点匹配已经匹配到的roadLink如果能匹配到需要将该点记录如果无法匹配则需要评估已匹配的link是否需要被剔除 // 尝试用当前位置点匹配已经匹配到的roadLink如果能匹配到需要将该点记录如果无法匹配则需要评估已匹配的link是否需要被剔除
if (!roadMatchEntityList.isEmpty()) { if (!roadMatchEntityList.isEmpty()) {
// 因为单个点位只能匹配一条任务需要获取当前点位距离所有任务最近的距离
roadMatchEntityList.stream().forEach(it->it.setCurrentLineDistance(GeometryTools.createGeometry(it.getGeometry()).distance(currentPoint)));
// 筛选出本次距离最近的线
RoadMatchEntity minRoadMatchEntity = roadMatchEntityList.stream().min((o1, o2)-> {
if (o1.getCurrentLineDistance()<o2.getCurrentLineDistance()){
return -1;
} else if (o1.getCurrentLineDistance()==o2.getCurrentLineDistance()) {
return 0;
} else {
return 1;
}
}).get();
List<RoadMatchEntity> unMatchList = new ArrayList<>(); List<RoadMatchEntity> unMatchList = new ArrayList<>();
Map<Integer, RoadMatchEntity> finishEntityMap = new HashMap<>(); Map<Integer, RoadMatchEntity> finishEntityMap = new HashMap<>();
double finalMatchStartDistance = matchStartDistance; double finalMatchStartDistance = matchStartDistance;
roadMatchEntityList.stream().forEach( roadMatchEntityList.stream().forEach(
roadMatchEntity -> { roadMatchEntity -> {
boolean isMatch=GeometryTools.createGeometry(roadMatchEntity.getGeometry()).distance(currentPoint)< finalMatchStartDistance; // 当前点位是否可以和link匹配到 double currentDistance = roadMatchEntity.getCurrentLineDistance();
if (isMatch) { // 可以匹配到 boolean isMatch=currentDistance<= finalMatchStartDistance; // 当前点位是否可以和link匹配到
if (minRoadMatchEntity.getId() == roadMatchEntity.getId()&&isMatch) { // 可以匹配到,并且该条数据还是最近的点
roadMatchEntity.setMatchCount(roadMatchEntity.getMatchCount()+1); roadMatchEntity.setMatchCount(roadMatchEntity.getMatchCount()+1);
roadMatchEntity.setUnMatchCount(0); // 有匹配的数据则连续未匹配个数归0 roadMatchEntity.setUnMatchCount(0); // 有匹配的数据则连续未匹配个数归0
roadMatchEntity.getMatchPointList().add(new MyCoordinate(currentPoint.getX(), currentPoint.getY())); roadMatchEntity.getMatchPointList().add(new MyCoordinate(currentPoint.getX(), currentPoint.getY()));
// 匹配到终点或匹配距离超过90% double currentEndDistance = currentPoint.distance(GeometryTools.createGeometry(roadMatchEntity.getePoint())); // 当前距离终点的距离
if (roadMatchEntity.getMatchPointList().size()>=2&&GeometryTools.getLineStringByMyCoordinate(roadMatchEntity.getMatchPointList()).getLength()/roadMatchEntity.getLength()>=MATCH_CONFIRM_FINISH_BUFFER // 记录本次的匹配距离如果本次匹配距离大于上一次且上一次匹配距离不为0则结束匹配否则继续等待匹配设置过EndMathchTime的数据即为可以结束匹配的数据下一次如果未匹配也可以结束
|| currentPoint.distance(GeometryTools.createGeometry(roadMatchEntity.getePoint()))<= finalMatchStartDistance) { if (roadMatchEntity.getEndMathchTime()>0/*endMatchTime不为0说明该数据已经匹配到终点*/&&currentEndDistance>roadMatchEntity.getLastEndDistance()) {
roadMatchEntity.setEndMathchTime(System.currentTimeMillis());
finishEntityMap.put(roadMatchEntity.getId(), roadMatchEntity); finishEntityMap.put(roadMatchEntity.getId(), roadMatchEntity);
} }
} else { // 无法匹配 // 匹配到终点或匹配距离超过90%
// 将无法匹配的点位个数记录到对象中 if (roadMatchEntity.getMatchPointList().size()>=2&&GeometryTools.getLineStringByMyCoordinate(roadMatchEntity.getMatchPointList()).getLength()/roadMatchEntity.getLength()>=MATCH_CONFIRM_FINISH_BUFFER
roadMatchEntity.setUnMatchCount(roadMatchEntity.getUnMatchCount()+1); || currentEndDistance<= finalMatchStartDistance) {
roadMatchEntity.setMatchCount(0); roadMatchEntity.setEndMathchTime(System.currentTimeMillis());
roadMatchEntity.getUnMatchPointList().add(new MyCoordinate(currentPoint.getX(), currentPoint.getY())); // 匹配到终点后记录该条数据的最新一次匹配距离当下一次匹配距离大于当前距离则认为该数据完全匹配结束匹配
// 判断当前是否存在已匹配的点 roadMatchEntity.setLastEndDistance(currentEndDistance);
if (roadMatchEntity.getMatchPointList().size()>1) { // 存在匹配的点超过1个根据长度判断 }
if (GeometryTools.getLineStringByMyCoordinate(roadMatchEntity.getMatchPointList()).getLength()/roadMatchEntity.getLength()>UNMATCH_GIVE_UP_DISTANCE_BUFFER) { } else { // 无法匹配或当前道路并不是距离最近的数据
// 匹配距离超过20%根据匹配点和未匹配点个数的对比率判断是否需要放弃 // 该数据未匹配但是如果此前已经匹配到结束点则仍然认为匹配成功
if (((float)roadMatchEntity.getUnMatchPointList().size())/roadMatchEntity.getMatchPointList().size()>UNMATCH_COUNT_BUFFER) { if (roadMatchEntity.getEndMathchTime()>0) {
unMatchList.add(roadMatchEntity); finishEntityMap.put(roadMatchEntity.getId(), roadMatchEntity);
} else {
// 将无法匹配的点位个数记录到对象中
roadMatchEntity.setUnMatchCount(roadMatchEntity.getUnMatchCount()+1);
roadMatchEntity.setMatchCount(0);// 设置连续匹配的数据个数为0
roadMatchEntity.getUnMatchPointList().add(new MyCoordinate(currentPoint.getX(), currentPoint.getY()));
// 判断当前是否存在已匹配的点
if (roadMatchEntity.getMatchPointList().size()>1) { // 存在匹配的点超过1个根据长度判断
if (GeometryTools.getLineStringByMyCoordinate(roadMatchEntity.getMatchPointList()).getLength()/roadMatchEntity.getLength()>UNMATCH_GIVE_UP_DISTANCE_BUFFER) {
// 匹配距离超过20%根据匹配点和未匹配点个数的对比率判断是否需要放弃
if (((float)roadMatchEntity.getUnMatchPointList().size())/roadMatchEntity.getMatchPointList().size()>UNMATCH_COUNT_BUFFER) {
unMatchList.add(roadMatchEntity);
}
} else {// 当前匹配距离不超过20%则必须有连续多个点未匹配才可以放弃该Link
if (roadMatchEntity.getUnMatchCount()>UNMATCH_BUFFER_MIDDLE_BUFFER) {
unMatchList.add(roadMatchEntity);
}
} }
} else {// 当前匹配距离不超过20%则必须有连续多个点未匹配才可以放弃该Link } else { // 从未匹配过的数据
if (roadMatchEntity.getUnMatchCount()>UNMATCH_BUFFER_MIDDLE_BUFFER) { // 未匹配个数超过指定阈值也认为数据不匹配
unMatchList.add(roadMatchEntity); if (roadMatchEntity.getMatchPointList().size()==0) { // 已匹配的个数为0
} if (roadMatchEntity.getUnMatchCount()>UNMATCH_BUFFER_START_BUFFER) {
} unMatchList.add(roadMatchEntity);
} else { // 从未匹配过的数据 }
// 未匹配个数超过指定阈值也认为数据不匹配 } else if (roadMatchEntity.getMatchPointList().size()==1) { // 已匹配的个数为1
if (roadMatchEntity.getMatchPointList().size()==0) { // 已匹配的个数为0 if (roadMatchEntity.getUnMatchCount()>UNMATCH_BUFFER_MIDDLE_BUFFER) {
if (roadMatchEntity.getUnMatchCount()>UNMATCH_BUFFER_START_BUFFER) { unMatchList.add(roadMatchEntity);
unMatchList.add(roadMatchEntity); }
}
} else if (roadMatchEntity.getMatchPointList().size()==1) { // 已匹配的个数为1
if (roadMatchEntity.getUnMatchCount()>UNMATCH_BUFFER_MIDDLE_BUFFER) {
unMatchList.add(roadMatchEntity);
} }
} }
} }
@ -727,6 +770,9 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
} }
// TODO 完成的entity数据需要自动生成对应的数据还需要自动复制对应的照片通知服务器采集完成 // TODO 完成的entity数据需要自动生成对应的数据还需要自动复制对应的照片通知服务器采集完成
finishRoadTask(finishEntityMap); finishRoadTask(finishEntityMap);
// 语音提示用户
mediaPlayer.start();
systemTTS.playText("拍摄完成");
} }
if (!unMatchList.isEmpty()) { if (!unMatchList.isEmpty()) {
@ -1278,6 +1324,9 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
if (gpsUtils!=null) { if (gpsUtils!=null) {
gpsUtils.unRegisterAllListener(); gpsUtils.unRegisterAllListener();
} }
if (mediaPlayer!=null) {
mediaPlayer.release();
}
} }
@Override @Override

View File

@ -30,7 +30,8 @@ public class RoadMatchEntity implements Serializable {
private String ePoint; // 起点 private String ePoint; // 起点
private long startMatchTime; // 开始匹配的时间 private long startMatchTime; // 开始匹配的时间
private long endMathchTime; // 结束匹配的时间 private long endMathchTime; // 结束匹配的时间
private double lastDistance=0; // 上次匹配到的距离 private double currentLineDistance=0f; // 当前匹配到的距离道路线的距离
private double lastEndDistance=0f; // 上次匹配到的距离终点的距离
private int matchCount; // <连续>匹配到的点位个数 private int matchCount; // <连续>匹配到的点位个数
private int unMatchCount; // <连续>未匹配到的点位个数 private int unMatchCount; // <连续>未匹配到的点位个数
private List<MyCoordinate> matchPointList = new ArrayList<>(); // 已匹配的点位列表 private List<MyCoordinate> matchPointList = new ArrayList<>(); // 已匹配的点位列表
@ -113,12 +114,12 @@ public class RoadMatchEntity implements Serializable {
this.endMathchTime = endMathchTime; this.endMathchTime = endMathchTime;
} }
public double getLastDistance() { public double getLastEndDistance() {
return lastDistance; return lastEndDistance;
} }
public void setLastDistance(double lastDistance) { public void setLastEndDistance(double lastEndDistance) {
this.lastDistance = lastDistance; this.lastEndDistance = lastEndDistance;
} }
public int getMatchCount() { public int getMatchCount() {
@ -153,6 +154,14 @@ public class RoadMatchEntity implements Serializable {
this.unMatchPointList = unMatchPointList; this.unMatchPointList = unMatchPointList;
} }
public double getCurrentLineDistance() {
return currentLineDistance;
}
public void setCurrentLineDistance(double currentLineDistance) {
this.currentLineDistance = currentLineDistance;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -1,9 +1,9 @@
package com.navinfo.outdoor.http; package com.navinfo.outdoor.http;
public class HttpInterface { public class HttpInterface {
public static final String IP1 = "http://172.23.138.133:9999/m4";//测试接口 public static final String IP = "http://172.23.138.133:9999/m4";//测试接口
public static final String IP2 = "http://dtxbmaps.navinfo.com/dtxb/dev/m4";//测试接口-外网 public static final String IP2 = "http://dtxbmaps.navinfo.com/dtxb/dev/m4";//测试接口-外网
public static final String IP = "http://dtxbmaps.navinfo.com/dtxb/m4";//正式接口 public static final String IP1 = "http://dtxbmaps.navinfo.com/dtxb/m4";//正式接口
public static final String USER_PATH = "/user/";//我的 public static final String USER_PATH = "/user/";//我的
public static final String MSG_LIST_PATH = "/msgList/";//发现 public static final String MSG_LIST_PATH = "/msgList/";//发现
public static final String USER_LOGIN_PATH = "/userlogin/";//登录 public static final String USER_LOGIN_PATH = "/userlogin/";//登录

Binary file not shown.