isapi_smart_fieldDetection.go 6.5 KB

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