CBFA.go 2.7 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 >= 20 && xj <= 50 && 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-1 && objValue[1][this_startFrame_index1] > 0 && objValue[1][this_startFrame_index1] < yi && objValue[0][this_startFrame_index2] >= 1 && objValue[0][this_startFrame_index2] < xj-1 && objValue[1][this_startFrame_index2] > 0 && (this_type != 100.0) { //简化条件
  49. return true
  50. }
  51. }
  52. } else {
  53. continue
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
  60. return false
  61. }
  62. func Topic() string {
  63. return "/tpperception"
  64. }
  65. // 禁止存在下划线_
  66. func Label() string {
  67. return "CBFA"
  68. }
  69. func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionObjects) string {
  70. defer func() {
  71. if r := recover(); r != nil {
  72. fmt.Println("Recovered from panic:", r)
  73. }
  74. }()
  75. YawofCicvLocation, ok1 = shareVars.Load("YawOfCicvLocation")
  76. if !ok1 {
  77. return ""
  78. }
  79. yaw = YawofCicvLocation.(float64)
  80. Framenum += 1
  81. ObjDicOfTpperception, ok2 = shareVars.Load("ObjDicOfTpperception")
  82. if !ok2 {
  83. return ""
  84. }
  85. objDic = ObjDicOfTpperception.(map[uint32][][]float32)
  86. for objId, objValue := range objDic {
  87. if len(objValue[0]) <= 10 || !isCrossAndOcclusion(objId, objValue, ObjectSlice) {
  88. continue
  89. }
  90. return Label()
  91. }
  92. return ""
  93. }