CBNA.go 2.6 KB

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