Skip to main content

AI检测使用说明


demo for AI detect

Open AI Detect

val createKey = KeyTools.createKey(AITrackingKey.KeySecurityIntelligentDetectEnter)

val lensTypeEnum = getLensType(aiLensType)
val droneLensId = drone.getAbilitySetManager().getCameraAbilitySetManager().getLenId(lensTypeEnum, drone.getGimbalDeviceType())
val bean = AIDetectConfigBean().apply {
sceneType = AiDetectSceneTypeEnum.SCENE_TYPE_UNIVERSAL
val targetList = arrayListOf<Int>()
targetList.add(DetectTargetEnum.PERSON.value)
targetList.add(DetectTargetEnum.CAR.value)
targetList.add(DetectTargetEnum.VEHICLE.value)
targetList.add(DetectTargetEnum.BOAT.value)

lensId = droneLensId ?: 0
}
SDKLog.i(TAG, "entry AI")

drone.getKeyManager().performAction(createKey, bean, callback = object : CommonCallbacks.CompletionCallbackWithParam<Void> {
override fun onSuccess(t: Void?) {
SDKLog.i(TAG, "entry AI success")
callback.invoke(true)
}

override fun onFailure(error: IAutelCode, msg: String?) {
SDKLog.i(TAG, "entry AI fail")
callback.invoke(false)
}
})

private fun getLensType(aiLensType: Int): LensTypeEnum {
return when (aiLensType) {
0 -> {
LensTypeEnum.Zoom
}
1 -> {
LensTypeEnum.Thermal
}
2 -> {
LensTypeEnum.NightVision
}
else -> {
LensTypeEnum.Zoom
}
}
}

Close AI Detect

val createKey =
KeyTools.createKey(AITrackingKey.KeySecurityIntelligentDetectExit)
DeviceManager.getDeviceManager().getFirstDroneDevice()?.getKeyManager()
?.performAction(createKey,
null,
object : CommonCallbacks.CompletionCallbackWithParam<Void> {
override fun onSuccess(t: Void?) {
Log.d(TAG, "[exitTrackingMission][onSuccess]")
binding.layoutTrack.visibility = View.GONE
}

override fun onFailure(error: IAutelCode, msg: String?) {
Log.d(TAG, "[exitTrackingMission][onFailure][error]$error")
}
})

AI Detect Result track

var euls: DoubleArray = DoubleArray(3)
var fov: DoubleArray = DoubleArray(2)
var msl: Double = 0.0
var robot_geo: DoubleArray = DoubleArray(3)
var point_org: DoubleArray = DoubleArray(3)
var camera_matrix: DoubleArray = DoubleArray(4)
var laserDis: Double = 0.0

private val trackListener = object : CommonCallbacks.KeyListener<DetectTrackNotifyBean> {
override fun onValueChange(
oldValue: DetectTrackNotifyBean?,
newValue: DetectTrackNotifyBean,
) {
newValue.objNum //见DetectTrackNotifyBean

newValue.infoList?.forEach {
it.startX// 见DetectObjectBean
it.type //DtectTargetEnum.CAR.value
}

euls = getEul(DeviceManager.getFirstDroneDevice())
robot_geo = getRobotGeo(DeviceManager.getFirstDroneDevice())
point_org = getHomePoint(DeviceManager.getFirstDroneDevice())
msl = getMSL(DeviceManager.getFirstDroneDevice())
laserDis = getDis(DeviceManager.getFirstDroneDevice())
camera_matrix = getCameraMatrix(newValue.resolutionWidth, newValue.resolutionHeight)

newValue.infoList?.forEach { detectBean ->
val obj = UploadDetectBean.InputObjects()
obj.tracker_id = "${detectBean.objectId}"
obj.cls_id = detectBean.type
obj.bbox = Bbox().apply {
x = detectBean.startX
y = detectBean.startY
w = detectBean.width
h = detectBean.height
}
obj.timestamp = SystemClock.elapsedRealtime()
obj.pic = "None"
val gps = AIJni.getGpsFromScreenWithXY(
euls,
robot_geo,
point_org,
laserDis,
camera_matrix,
msl,
detectBean.startX.toDouble() + detectBean.width / 2f,
detectBean.startY.toDouble() + detectBean.height / 2f
)
obj.pos = GlobalPos().apply {
altitude = gps?.z?.toFloat() ?: 0f
latitude = gps?.x?.toFloat() ?: 0f
longitude = gps?.y?.toFloat() ?: 0f
}
obj.locked = false
objCnts.add(obj)
}
}
}

val key = KeyTools.createKey(AIServiceKey.KeyAiDetectTarget)
AutelLog.i(TAG, "register track listener")
DeviceManager.getDeviceManager().getFirstDroneDevice()?.getKeyManager()?.listen(key, trackListener)


private fun getEul(device: IAutelDroneDevice): DoubleArray {
val eul = DoubleArray(3)
device.getDeviceStateData().flightControlData.let {
eul[0] = it.gimbalAttitudeYaw.toDouble()
eul[1] = it.gimbalAttitudePitch.toDouble()
eul[2] = it.gimbalAttitudeRoll.toDouble()
}
return eul
}


private fun getRobotGeo(device: IAutelDroneDevice): DoubleArray {
val robot_geos = DoubleArray(3)
device.getDeviceStateData().flightControlData.let {
robot_geos[0] = it.droneLatitude
robot_geos[1] = it.droneLongitude
robot_geos[2] = it.altitudeMSL.toDouble()
}
return robot_geos

}

private fun getHomePoint(device: IAutelDroneDevice): DoubleArray {
val homePoints = DoubleArray(3)
device.getDeviceStateData().flightControlData.let {
homePoints[0] = it.homeLatitude
homePoints[1] = it.homeLongitude
homePoints[2] = 0.0
}
return homePoints
}

private fun getDis(device: IAutelDroneDevice): Double {
var laserDis = 0.0
device.getDeviceStateData().flightControlData.let {
laserDis = it.laserDistance.toDouble() / 100.0
}
return laserDis
}


private fun getMSL(device: IAutelDroneDevice): Double {
var msl = 0.0
device.getDeviceStateData().flightControlData.let {
msl = it.altitudeMSL.toDouble()
}
return msl
}

private fun getFovs(device: IAutelDroneDevice): DoubleArray {
val fov = DoubleArray(2)
device.getDeviceStateData().gimbalDataMap[device.getGimbalDeviceType()].let {
fov[0] = it?.cameraData?.cameraInfoList?.first()?.fovH?.toDouble() ?: 0.0
fov[1] = it?.cameraData?.cameraInfoList?.first()?.fovV?.toDouble() ?: 0.0

}
return fov
}


private fun getCameraMatrix(width: Int, height: Int): DoubleArray {
val fovs = getFovs(DeviceManager.getFirstDroneDevice())
return doubleArrayOf(
fovs[0], fovs[1], width.toDouble(), height.toDouble()
)
}

data class DetectTrackNotifyBean(
/**
* 分辨率宽度
*/
var resolutionWidth: Int = 0,
/**
* 分辨率高度
*/
var resolutionHeight: Int = 0,
/**
* 数量
*/
var objNum: Int = 0,
/**
* 跟踪框数组
*/
var infoList: List<DetectObjectBean>? = null,
)


data class DetectObjectBean(
/**
* 目标的像素坐标x
*/
var startX: Float = 0f,
/**
* 目标的像素坐标y
*/
var startY: Float = 0f,
/**
* 目标框宽度
*/
var width: Float = 0f,
/**
* 目标框的高度
*/
var height: Float = 0f,
/**
* 目标的类型
*/
var type: Int = 0,
/**
* 目标跟踪类型
*/
var status: Int = 0,

/**
* 装 特征标签 取值: 正常着装 红 1 装 绿框
*
*/
var camouflage: Boolean = false,
/**
* 持枪 特征标 取值: 未持枪(不显) 1 持枪
*
*/
var gun: Boolean = false,
/**
* 背包 特征签 取值: 未背《不显示)1 事背包
*
*/
var tacticalBackpack: Boolean = false,
/**
* 姿态取值: 0 站立 1 坐 2 平 3 骑行4弯腰 5 下蹲 6俯卧 7 乘车 8 正常
*/

var pose: PoseTypeEnum = PoseTypeEnum.STANDUP,
/**
* 动作 动作标签 取值:0 投降 1 举手 2 射击 3投掷 4 抱头 5 背手 6 正常
*
* */
var actions: ActionEnum = ActionEnum.COMMENT,
/**
* 目标ID
*/
var objectId: Int = 0,
/**
* 假人
*/
var dummp_soldier: Boolean = false,

/**
*仅对目标为人 危险等级 1,2,3,4,5 1-最高 5-最低
*/
var danger_level: DangerLevelEnum = DangerLevelEnum.NO_DANGEROUS,
)


enum class DetectTargetEnum(var value: Int, var info: String) {

BACKGROUND(0, "背景"), // 背景
ANIMAL(1, "动物"), // 动物


/**
* 船
*/
BOAT(2, "船"), // 船

/**
* 小车
*/
CAR(3, "小车"), // 小车

/**
* 行人
*/
PERSON(4, "行人"), // 行人
/**
* 骑行者
*/
RIDER(5, "骑行者"),

/**
* 大车
*/
VEHICLE(6, "大车"), // 大车

/**
* 绝缘端子
*/
INSULATOR(10, "Insulated terminal"),

/**
* 横担端挂点
*/
CROSSARMPOINT(11, "Cross arm end hanging point"),

/**
* 导线端挂点
*/
WIREPOINT(12, "Wire end hanging point"),

/**
* 导地线挂点
*/
EARTHWIREPOINT(13, "Ground wire hanging point"),

/**
* 导地线挂点
*/
DAMPER(14, "Vibration hammer"),

/**
* 导地线挂点
*/
POLE(15, "Electric pole"),

/**
* 导地线挂点
*/
TOWER(16, "Tower body"),

/**
* 导地线挂点
*/
TOWER_HEAD(17, "Tower head"),

/**
* 导地线挂点
*/
TOWER_FOOT(18, "Taki"),
}