isapi_smart_lineDetection.go 6.4 KB

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