CPNCO.go 2.6 KB

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