isapi_smart_lineDetection.go 6.3 KB

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