CBNAO.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "fmt"
  5. "sync"
  6. )
  7. var (
  8. Framenum int64 = 0
  9. YawofCicvLocation any
  10. ObjDicOfTpperception any
  11. objDic = make(map[uint32][][]float32)
  12. yaw float64
  13. objId uint32
  14. obj [][]float32
  15. ok1 bool
  16. ok2 bool
  17. ObjectSlice = make(map[uint32][][]float32)
  18. )
  19. func findIndex(lst []float32, target float32) int {
  20. for i, v := range lst {
  21. if v == target {
  22. return i
  23. }
  24. }
  25. return -1
  26. }
  27. func isCrossAndOcclusion(id uint32, ObjectList [][]float32, ObjectSlice map[uint32][][]float32) bool {
  28. for i := 0; i < len(ObjectList[0]); i++ {
  29. xi := ObjectList[0][i]
  30. yi := ObjectList[1][i]
  31. diff_hi := ObjectList[7][i]
  32. Type := ObjectList[6][0]
  33. if xi >= 0 && yi <= -3 && diff_hi >= 0 && Type != 100.0 {
  34. startFrame1 := ObjectList[5][i]
  35. for j := 0; j < len(ObjectList[0])-i-1; j++ {
  36. xj := ObjectList[0][j]
  37. yj := ObjectList[1][j]
  38. diff_hj := ObjectList[7][j]
  39. if xj >= 0 && xj <= 25 && yj >= 1 && diff_hj >= 0 {
  40. startFrame2 := ObjectList[5][j]
  41. for this_id, objValue := range ObjectSlice {
  42. if this_id != id {
  43. this_startFrame_index1 := findIndex(objValue[5], startFrame1)
  44. this_startFrame_index2 := findIndex(objValue[5], startFrame2)
  45. this_type := objValue[6][0]
  46. //fmt.Println(objValue[0][this_startFrame_index2], xj)
  47. if this_startFrame_index1 != -1 && this_startFrame_index2 != -1 {
  48. //if objValue[0][this_startFrame_index1] >= 2 && objValue[0][this_startFrame_index1] < xi-5 && objValue[1][this_startFrame_index1] < 0 && objValue[1][this_startFrame_index1] > yi && objValue[0][this_startFrame_index2] >= 1 && objValue[0][this_startFrame_index2] < xj-3 && objValue[1][this_startFrame_index2] < 0 && (this_type == 2.0 || this_type == 3.0) { //理论条件
  49. if objValue[0][this_startFrame_index1] >= 2 && objValue[0][this_startFrame_index1] < xi-5 && objValue[1][this_startFrame_index1] < 0 && objValue[1][this_startFrame_index1] > yi && objValue[0][this_startFrame_index2] >= 1 && objValue[0][this_startFrame_index2] < xj-3 && objValue[1][this_startFrame_index2] < 0 && (this_type != 100.0) { //简化条件
  50. return true
  51. }
  52. }
  53. } else {
  54. continue
  55. }
  56. }
  57. }
  58. }
  59. }
  60. }
  61. return false
  62. }
  63. func Topic() string {
  64. return "/tpperception"
  65. }
  66. // 禁止存在下划线_
  67. func Label() string {
  68. return "CBNAO"
  69. }
  70. func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionObjects) string {
  71. defer func() {
  72. if r := recover(); r != nil {
  73. fmt.Println("Recovered from panic:", r)
  74. }
  75. }()
  76. YawofCicvLocation, ok1 = shareVars.Load("YawOfCicvLocation")
  77. if !ok1 {
  78. return ""
  79. }
  80. yaw = YawofCicvLocation.(float64)
  81. Framenum += 1
  82. ObjDicOfTpperception, ok2 = shareVars.Load("ObjDicOfTpperception")
  83. if !ok2 {
  84. return ""
  85. }
  86. objDic = ObjDicOfTpperception.(map[uint32][][]float32)
  87. for objId, objValue := range objDic {
  88. if len(objValue[0]) <= 10 || !isCrossAndOcclusion(objId, objValue, ObjectSlice) {
  89. continue
  90. }
  91. return Label()
  92. }
  93. return ""
  94. }