isapi_smart_lineDetection.go 6.3 KB

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