isapi_smart_regionEntrance.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package isapi
  2. import (
  3. "encoding/json"
  4. "encoding/xml"
  5. "github.com/sirupsen/logrus"
  6. )
  7. // RegionEntranceParam 进入区域
  8. type RegionEntranceParam struct {
  9. ID string `xml:"id" json:"id"`
  10. Enabled string `xml:"enabled" json:"enabled"`
  11. NormalizedScreenSize struct {
  12. NormalizedScreenWidth string `xml:"normalizedScreenWidth" json:"normalizedScreenWidth"`
  13. NormalizedScreenHeight string `xml:"normalizedScreenHeight" json:"normalizedScreenHeight"`
  14. } `xml:"normalizedScreenSize" json:"normalizedScreenSize"`
  15. RegionEntranceRegionList struct {
  16. Size string `xml:"size,attr" json:"size"`
  17. RegionEntranceRegion []struct {
  18. ID string `xml:"id" json:"id"`
  19. SensitivityLevel string `xml:"sensitivityLevel" json:"sensitivityLevel"`
  20. DetectionTarget string `xml:"detectionTarget" json:"detectionTarget"`
  21. AlarmConfidence string `xml:"alarmConfidence" json:"alarmConfidence"`
  22. RegionCoordinatesList struct {
  23. RegionCoordinates []struct {
  24. PositionX string `xml:"positionX" json:"positionX"`
  25. PositionY string `xml:"positionY" json:"positionY"`
  26. } `xml:"RegionCoordinates" json:"RegionCoordinates"`
  27. } `xml:"RegionCoordinatesList" json:"RegionCoordinatesList"`
  28. } `xml:"RegionEntranceRegion" json:"RegionEntranceRegion"`
  29. } `xml:"RegionEntranceRegionList" json:"RegionEntranceRegionList"`
  30. IsSupportMultiScene string `xml:"isSupportMultiScene" json:"isSupportMultiScene"`
  31. IsSupportHumanMisinfoFilter string `xml:"isSupportHumanMisinfoFilter" json:"isSupportHumanMisinfoFilter"`
  32. IsSupportVehicleMisinfoFilter string `xml:"isSupportVehicleMisinfoFilter" json:"isSupportVehicleMisinfoFilter"`
  33. IsSupportTargetMultiSelect string `xml:"isSupportTargetMultiSelect" json:"isSupportTargetMultiSelect"`
  34. }
  35. func (c *Client) GetRegionEntranceCap() (resp RegionEntranceCap, err error) {
  36. bytes, err := c.CommonGet("/ISAPI/Smart/regionEntrance/1/capabilities")
  37. if err != nil {
  38. logrus.Error("请求出错", err)
  39. return
  40. }
  41. err = xml.Unmarshal(bytes, &resp)
  42. detection, _ := c.GetRegionEntrance()
  43. for i, v := range detection.RegionEntranceRegionList.RegionEntranceRegion {
  44. resp.RegionEntranceRegionList.RegionEntranceRegion[i].AlarmConfidence.Text = v.AlarmConfidence
  45. }
  46. return
  47. }
  48. func (c *Client) GetSizeRe() (resp SmartCalibrationList, err error) {
  49. bytes, err := c.CommonGet("/ISAPI/Smart/channels/1/calibrations/regionEntrance")
  50. if err != nil {
  51. logrus.Error("请求出错", err)
  52. return
  53. }
  54. err = xml.Unmarshal(bytes, &resp)
  55. return
  56. }
  57. func (c *Client) PutSizeRe(data []byte) (resp ResponseStatus, err error) {
  58. var info SmartCalibrationList
  59. err = json.Unmarshal(data, &info)
  60. if err != nil {
  61. logrus.Error(err)
  62. return ResponseStatus{}, err
  63. }
  64. marshal, err := xml.Marshal(info)
  65. if err != nil {
  66. logrus.Error(err)
  67. return ResponseStatus{}, err
  68. }
  69. respData, err := c.CommonPut(marshal, "/ISAPI/Smart/channels/1/calibrations/regionEntrance")
  70. if err != nil {
  71. logrus.Error(err)
  72. return ResponseStatus{}, err
  73. }
  74. err = xml.Unmarshal(respData, &resp)
  75. if err != nil {
  76. logrus.Error(err)
  77. return ResponseStatus{}, err
  78. }
  79. return
  80. }
  81. // GetRegionEntrance 获取区域侦测参数
  82. func (c *Client) GetRegionEntrance() (resp RegionEntranceParam, err error) {
  83. bytes, err := c.CommonGet("/ISAPI/Smart/regionEntrance/1")
  84. if err != nil {
  85. logrus.Error("请求出错", err)
  86. return
  87. }
  88. err = xml.Unmarshal(bytes, &resp)
  89. return
  90. }
  91. // PutRegionEntrance 配置区域侦测参数
  92. func (c *Client) PutRegionEntrance(data []byte) (resp ResponseStatus, err error) {
  93. var info RegionEntranceParam
  94. err = json.Unmarshal(data, &info)
  95. if err != nil {
  96. logrus.Error(err)
  97. return ResponseStatus{}, err
  98. }
  99. marshal, err := xml.Marshal(info)
  100. if err != nil {
  101. logrus.Error(err)
  102. return ResponseStatus{}, err
  103. }
  104. respData, err := c.CommonPut(marshal, "/ISAPI/Smart/regionEntrance/1")
  105. if err != nil {
  106. logrus.Error(err)
  107. return ResponseStatus{}, err
  108. }
  109. err = xml.Unmarshal(respData, &resp)
  110. if err != nil {
  111. logrus.Error(err)
  112. return ResponseStatus{}, err
  113. }
  114. return
  115. }
  116. type RegionEntranceCap struct {
  117. ID string `xml:"id"`
  118. Enabled struct {
  119. Text string `xml:",chardata" json:"value"`
  120. Opt string `xml:"opt,attr" json:"opt"`
  121. } `xml:"enabled" json:"enabled"`
  122. NormalizedScreenSize struct {
  123. NormalizedScreenWidth string `xml:"normalizedScreenWidth" json:"normalizedScreenWidth"`
  124. NormalizedScreenHeight string `xml:"normalizedScreenHeight" json:"normalizedScreenHeight"`
  125. } `xml:"normalizedScreenSize" json:"normalizedScreenSize"`
  126. RegionEntranceRegionList struct {
  127. Size string `xml:"size,attr" json:"size"`
  128. RegionEntranceRegion []struct {
  129. ID string `xml:"id" json:"id"`
  130. SensitivityLevel struct {
  131. Text string `xml:",chardata" json:"value"`
  132. Min string `xml:"min,attr" json:"min"`
  133. Max string `xml:"max,attr" json:"max"`
  134. } `xml:"sensitivityLevel" json:"sensitivityLevel"`
  135. RegionCoordinatesList struct {
  136. RegionCoordinates []struct {
  137. PositionX string `xml:"positionX" json:"positionX"`
  138. PositionY string `xml:"positionY" json:"positionY"`
  139. } `xml:"RegionCoordinates" json:"RegionCoordinates"`
  140. } `xml:"RegionCoordinatesList" json:"RegionCoordinatesList"`
  141. MinRegionCoordinatesNum string `xml:"minRegionCoordinatesNum" json:"minRegionCoordinatesNum"`
  142. MaxRegionCoordinatesNum string `xml:"maxRegionCoordinatesNum" json:"maxRegionCoordinatesNum"`
  143. DetectionTarget struct {
  144. Text string `xml:",chardata" json:"value"`
  145. Opt string `xml:"opt,attr" json:"opt"`
  146. } `xml:"detectionTarget" json:"detectionTarget"`
  147. AlarmConfidence struct {
  148. Text string `xml:",chardata" json:"value"`
  149. Opt string `xml:"opt,attr" json:"opt"`
  150. Def string `xml:"def,attr" json:"def"`
  151. } `xml:"alarmConfidence" json:"alarmConfidence"`
  152. } `xml:"RegionEntranceRegion" json:"RegionEntranceRegion"`
  153. } `xml:"RegionEntranceRegionList" json:"RegionEntranceRegionList"`
  154. IsSupportMultiScene string `xml:"isSupportMultiScene" json:"isSupportMultiScene"`
  155. IsSupportHumanMisinfoFilter string `xml:"isSupportHumanMisinfoFilter" json:"isSupportHumanMisinfoFilter"`
  156. IsSupportVehicleMisinfoFilter string `xml:"isSupportVehicleMisinfoFilter" json:"isSupportVehicleMisinfoFilter"`
  157. IsSupportTargetMultiSelect string `xml:"isSupportTargetMultiSelect" json:"isSupportTargetMultiSelect"`
  158. IsSupportAllDayUpload string `xml:"isSupportAllDayUpload" json:"isSupportAllDayUpload"`
  159. }