机器视觉地图绘制点
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package com.mogo.module.common.constants;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/10/27
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
class AdasRecognizedType {
|
||||
//背景
|
||||
public static final int classIdBackground = 0;
|
||||
//人
|
||||
public static final int classIdPerson = 1;
|
||||
//自行车
|
||||
public static final int classIdBicycle = 2;
|
||||
//小轿车
|
||||
public static final int classIdCar = 3;
|
||||
//摩托车
|
||||
public static final int classIdMoto = 4;
|
||||
//红绿灯
|
||||
public static final int classIdTrafficSign = 5;
|
||||
//bus
|
||||
public static final int classIdTrafficBus = 6;
|
||||
//track
|
||||
public static final int classIdTrafficTruck = 8;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.mogo.module.common.constants;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/10/28
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
class DataTypes {
|
||||
/**
|
||||
* adas识别数据
|
||||
*/
|
||||
public static final String TYPE_MARKER_ADAS = "TYPE_MARKER_ADAS";
|
||||
|
||||
/**
|
||||
* 云端下发数据
|
||||
*/
|
||||
public static final String TYPE_MARKER_CLOUD_DATA = "TYPE_MARKER_CLOUD_DATA";
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package com.mogo.module.common.drawer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.module.common.ModuleNames;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.R;
|
||||
import com.mogo.module.common.constants.AdasRecognizedType;
|
||||
import com.mogo.module.common.constants.DataTypes;
|
||||
import com.mogo.service.adas.entity.ADASRecognizedListResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/10/28
|
||||
*
|
||||
* 绘制adas近景识别到的车辆
|
||||
*/
|
||||
class AdasRecognizedResultDrawer {
|
||||
|
||||
private static volatile AdasRecognizedResultDrawer sInstance;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private AdasRecognizedResultDrawer() {
|
||||
mContext = AbsMogoApplication.getApp();
|
||||
}
|
||||
|
||||
public static AdasRecognizedResultDrawer getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( AdasRecognizedResultDrawer.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new AdasRecognizedResultDrawer();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
private Object readResolve() {
|
||||
// 阻止反序列化,必须实现 Serializable 接口
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
// adas marker 缓存
|
||||
private Map< String, IMogoMarker > mAdasRecognizedMarkersCaches = new ConcurrentHashMap<>();
|
||||
|
||||
public void renderAdasRecognizedResult( List< ADASRecognizedListResult > resultList ) {
|
||||
if ( resultList == null || resultList.isEmpty() ) {
|
||||
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).removeMarkers( DataTypes.TYPE_MARKER_ADAS );
|
||||
return;
|
||||
}
|
||||
purgeAdasRecognizedData( resultList );
|
||||
for ( ADASRecognizedListResult recognizedListResult : resultList ) {
|
||||
if ( recognizedListResult == null ) {
|
||||
continue;
|
||||
}
|
||||
IMogoMarker marker = null;
|
||||
String uniqueKey = recognizedListResult.uuid;
|
||||
if ( mAdasRecognizedMarkersCaches.containsKey( uniqueKey ) ) {
|
||||
marker = mAdasRecognizedMarkersCaches.get( uniqueKey );
|
||||
}
|
||||
if ( marker == null || marker.isDestroyed() ) {
|
||||
marker = drawAdasRecognizedDataMarker( recognizedListResult );
|
||||
mAdasRecognizedMarkersCaches.put( uniqueKey, marker );
|
||||
}
|
||||
|
||||
List< MogoLatLng > points = new ArrayList<>();
|
||||
if ( recognizedListResult.latLonList != null
|
||||
|| recognizedListResult.latLonList.size() > 1 ) {
|
||||
for ( int j = 0; j < recognizedListResult.latLonList.size(); j++ ) {
|
||||
ADASRecognizedListResult.LatLon latLon = recognizedListResult.latLonList.get( j );
|
||||
if ( latLon == null ) {
|
||||
continue;
|
||||
}
|
||||
points.add( new MogoLatLng( latLon.lat, latLon.lon ) );
|
||||
}
|
||||
|
||||
} else {
|
||||
// 原来的点和新的点做一个数组进行平滑移动
|
||||
MogoLatLng latLng = marker.getPosition();
|
||||
ADASRecognizedListResult.LatLon latLon = recognizedListResult.latLonList.get( 0 );
|
||||
if ( latLon == null ) {
|
||||
continue;
|
||||
}
|
||||
points.add( latLng );
|
||||
points.add( new MogoLatLng( latLng.lat, latLon.lon ) );
|
||||
}
|
||||
if ( points.size() >= 1 ) {
|
||||
marker.startSmooth( points, 1000 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤adas数据中,不存在的 marker
|
||||
*
|
||||
* @param resultList
|
||||
*/
|
||||
private void purgeAdasRecognizedData( List< ADASRecognizedListResult > resultList ) {
|
||||
if ( resultList == null || resultList.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
if ( mAdasRecognizedMarkersCaches.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
Map< String, IMogoMarker > existMarker = new HashMap<>();
|
||||
for ( ADASRecognizedListResult recognizedListResult : resultList ) {
|
||||
if ( recognizedListResult == null ) {
|
||||
continue;
|
||||
}
|
||||
String uniqueKey = recognizedListResult.uuid;
|
||||
if ( mAdasRecognizedMarkersCaches.containsKey( uniqueKey ) ) {
|
||||
existMarker.put( uniqueKey, mAdasRecognizedMarkersCaches.get( uniqueKey ) );
|
||||
}
|
||||
}
|
||||
if ( !existMarker.isEmpty() ) {
|
||||
for ( String key : mAdasRecognizedMarkersCaches.keySet() ) {
|
||||
if ( !existMarker.containsKey( key ) ) {
|
||||
try {
|
||||
IMogoMarker marker = mAdasRecognizedMarkersCaches.remove( key );
|
||||
marker.destroy();
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IMogoMarker drawAdasRecognizedDataMarker( ADASRecognizedListResult recognizedListResult ) {
|
||||
if ( recognizedListResult == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( recognizedListResult.type == AdasRecognizedType.classIdBackground ) {
|
||||
|
||||
}
|
||||
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||
.owner( DataTypes.TYPE_MARKER_ADAS )
|
||||
.icon( BitmapFactory.decodeResource( mContext.getResources(), R.drawable.map_custom_ic_current_location2 ) )
|
||||
.position( new MogoLatLng( recognizedListResult.latLonList.get( 0 ).lat, recognizedListResult.latLonList.get( 0 ).lon ) );
|
||||
return MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).addMarker( ModuleNames.CARD_TYPE_ROAD_CONDITION, options );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package com.mogo.module.common.drawer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.module.common.ModuleNames;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.R;
|
||||
import com.mogo.module.common.constants.AdasRecognizedType;
|
||||
import com.mogo.module.common.constants.DataTypes;
|
||||
import com.mogo.module.common.entity.CloudLocationInfo;
|
||||
import com.mogo.module.common.entity.CloudRoadData;
|
||||
import com.mogo.module.common.entity.MogoSnapshotSetData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/10/28
|
||||
*
|
||||
* 云端数据绘制
|
||||
*/
|
||||
class SnapshotSetDataDrawer {
|
||||
|
||||
private static volatile SnapshotSetDataDrawer sInstance;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private SnapshotSetDataDrawer() {
|
||||
mContext = AbsMogoApplication.getApp();
|
||||
}
|
||||
|
||||
public static SnapshotSetDataDrawer getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( SnapshotSetDataDrawer.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new SnapshotSetDataDrawer();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
private Object readResolve() {
|
||||
// 阻止反序列化,必须实现 Serializable 接口
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
// 云端 marker 缓存
|
||||
private Map< String, IMogoMarker > mCloudSnapshotMarkersCaches = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* 其他车辆、rsu 车辆数据
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
public void renderSnapshotData( MogoSnapshotSetData data, boolean filterAdasData ) {
|
||||
if ( data == null || data.getAllList() == null || data.getAllList().isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
purgeCloudSnapshotData( data );
|
||||
for ( CloudRoadData cloudRoadData : data.getAllList() ) {
|
||||
if ( cloudRoadData == null ) {
|
||||
continue;
|
||||
}
|
||||
if ( filterAdasData && cloudRoadData.getDistance() < 50 ) {
|
||||
// 过滤 adas 识别的车辆
|
||||
continue;
|
||||
}
|
||||
IMogoMarker marker = null;
|
||||
String uniqueKey = cloudRoadData.getUniqueKey();
|
||||
if ( mCloudSnapshotMarkersCaches.containsKey( uniqueKey ) ) {
|
||||
marker = mCloudSnapshotMarkersCaches.get( uniqueKey );
|
||||
}
|
||||
if ( marker == null || marker.isDestroyed() ) {
|
||||
marker = drawSnapshotDataMarker( cloudRoadData );
|
||||
mCloudSnapshotMarkersCaches.put( uniqueKey, marker );
|
||||
}
|
||||
List< MogoLatLng > points = new ArrayList<>();
|
||||
if ( cloudRoadData.getCoordinates() != null
|
||||
|| cloudRoadData.getCoordinates().size() > 1 ) {
|
||||
for ( int j = 0; j < cloudRoadData.getCoordinates().size(); j++ ) {
|
||||
CloudLocationInfo poi = cloudRoadData.getCoordinates().get( j );
|
||||
if ( poi == null ) {
|
||||
continue;
|
||||
}
|
||||
double lat = poi.getLat();
|
||||
double lng = poi.getLon();
|
||||
points.add( new MogoLatLng( lat, lng ) );
|
||||
}
|
||||
|
||||
} else {
|
||||
points.add( marker.getPosition() );
|
||||
points.add( new MogoLatLng( cloudRoadData.getLat(), cloudRoadData.getLon() ) );
|
||||
}
|
||||
if ( points.size() >= 1 ) {
|
||||
marker.startSmooth( points, 1000 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤本次数据中,不存在的 marker
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
private void purgeCloudSnapshotData( MogoSnapshotSetData data ) {
|
||||
if ( data == null || data.getAllList() == null || data.getAllList().isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
if ( mCloudSnapshotMarkersCaches.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
Map< String, IMogoMarker > existMarker = new HashMap<>();
|
||||
for ( CloudRoadData cloudRoadData : data.getAllList() ) {
|
||||
if ( cloudRoadData == null ) {
|
||||
continue;
|
||||
}
|
||||
String uniqueKey = cloudRoadData.getUniqueKey();
|
||||
if ( mCloudSnapshotMarkersCaches.containsKey( uniqueKey ) ) {
|
||||
existMarker.put( uniqueKey, mCloudSnapshotMarkersCaches.get( uniqueKey ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !existMarker.isEmpty() ) {
|
||||
for ( String key : mCloudSnapshotMarkersCaches.keySet() ) {
|
||||
if ( !existMarker.containsKey( key ) ) {
|
||||
try {
|
||||
IMogoMarker marker = mCloudSnapshotMarkersCaches.remove( key );
|
||||
marker.destroy();
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IMogoMarker drawSnapshotDataMarker( CloudRoadData data ) {
|
||||
if ( data == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( data.getType() == AdasRecognizedType.classIdBackground ) {
|
||||
|
||||
}
|
||||
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||
.owner( DataTypes.TYPE_MARKER_CLOUD_DATA )
|
||||
.icon( BitmapFactory.decodeResource( mContext.getResources(), R.drawable.map_custom_ic_current_location2 ) )
|
||||
.position( new MogoLatLng( data.getLat(), data.getLon() ) );
|
||||
return MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).addMarker( ModuleNames.CARD_TYPE_ROAD_CONDITION, options );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user